heartcombo--simple_form/lib/simple_form/map_type.rb

17 lines
446 B
Ruby
Raw Normal View History

2011-01-05 19:52:49 +00:00
require 'active_support/core_ext/class/attribute'
2009-12-09 17:48:40 +00:00
module SimpleForm
module MapType
2011-01-05 19:52:49 +00:00
def self.extended(base)
base.class_attribute :mappings
base.mappings = {}
2009-12-09 17:48:40 +00:00
end
def map_type(*types)
map_to = types.extract_options![:to]
raise ArgumentError, "You need to give :to as option to map_type" unless map_to
self.mappings = mappings.merge types.each_with_object({}) { |t, m| m[t] = map_to }
2009-12-09 17:48:40 +00:00
end
end
end