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
|
|
|
|
|
2009-12-10 00:55:42 +00:00
|
|
|
def map_type(*types)
|
2010-09-27 02:21:30 +00:00
|
|
|
map_to = types.extract_options![:to]
|
|
|
|
raise ArgumentError, "You need to give :to as option to map_type" unless map_to
|
2011-03-29 18:46:08 +00:00
|
|
|
self.mappings = mappings.merge types.each_with_object({}) { |t, m| m[t] = map_to }
|
2009-12-09 17:48:40 +00:00
|
|
|
end
|
|
|
|
end
|
2010-09-27 02:21:30 +00:00
|
|
|
end
|