# File lib/dm-types/enum.rb, line 10 10: def initialize(model, name, options = {}) 11: @flag_map = {} 12: 13: flags = options.fetch(:flags, self.class.flags) 14: flags.each_with_index do |flag, i| 15: @flag_map[i + 1] = flag 16: end 17: 18: if self.class.accepted_options.include?(:set) && !options.include?(:set) 19: options[:set] = @flag_map.values_at(*@flag_map.keys.sort) 20: end 21: 22: super 23: end
# File lib/dm-types/enum.rb, line 29 29: def dump(value) 30: case value 31: when ::Array then value.collect { |v| dump(v) } 32: else flag_map.invert[value] 33: end 34: end
# File lib/dm-types/enum.rb, line 25 25: def load(value) 26: flag_map[value] 27: end
# File lib/dm-types/enum.rb, line 36 36: def typecast_to_primitive(value) 37: # Attempt to typecast using the class of the first item in the map. 38: case flag_map[1] 39: when ::Symbol then value.to_sym 40: when ::String then value.to_s 41: when ::Fixnum then value.to_i 42: else value 43: end 44: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.