Integer
# File lib/dm-types/enum.rb, line 11 def initialize(model, name, options = {}) @flag_map = {} flags = options.fetch(:flags, self.class.flags) flags.each_with_index do |flag, i| @flag_map[i.succ] = flag end if self.class.accepted_options.include?(:set) && !options.include?(:set) options[:set] = @flag_map.values_at(*@flag_map.keys.sort) end options[:max] = @flag_map.size super end
# File lib/dm-types/enum.rb, line 32 def dump(value) case value when ::Array then value.collect { |v| dump(v) } else flag_map.invert[value] end end
# File lib/dm-types/enum.rb, line 28 def load(value) flag_map[value] end
# File lib/dm-types/enum.rb, line 39 def typecast_to_primitive(value) # Attempt to typecast using the class of the first item in the map. case flag_map[1] when ::Symbol then value.to_sym when ::String then value.to_s when ::Fixnum then value.to_i else value end end
Generated with the Darkfish Rdoc Generator 2.