module FlatMap::OpenMapper::Mapping::ClassMethods
Mapping
class macros
Constants
- MAPPING_OPTIONS
Mapping-modifier options to distinguish options from mappings themselves:
Public Instance Methods
Define single or multiple mappings at a time. Usually, a Hash is passed in a form !{mapping_name => target_attribute}. All keys that are listed under {MAPPING_OPTIONS} will be extracted and used as modifiers for new mappings.
Also, mapping names may be listed as an array preceding the hash. In that case, its elements are treated as !{mapping_name => mapping_name} mapping elements.
Example:
map :brand, :account_source => :source, :format => :enum # is equivalent to: map :brand => :brand, :format => :enum map :account_source => :source, :format => :enum
# File lib/flat_map/open_mapper/mapping.rb, line 28 def map(*args) mapping_options = args.extract_options! mappings = mapping_options.slice!(*MAPPING_OPTIONS) mappings_from_array = args.zip(args).flatten mappings.merge!(Hash[*mappings_from_array]) unless mappings_from_array.empty? define_mappings(mappings, mapping_options) end
List of class mappings (mapping factories).
@return [Array<FlatMap::Mapping::Factory>]
# File lib/flat_map/open_mapper/mapping.rb, line 55 def mappings @mappings ||= [] end
Writer for mappings.
# File lib/flat_map/open_mapper/mapping.rb, line 60 def mappings=(val) @mappings = val end
Private Instance Methods
Define a set of mappings
, passed as a {Hash} with options
as modifiers. Eventually, adds a mapping factories to list of class mappings. Those factory objects are used to create actual mappings for specific mapper object.
@param [Hash] mappings @param [Hash] options @return [Array<FlatMap::Mapping::Factory>] list of mappings
# File lib/flat_map/open_mapper/mapping.rb, line 45 def define_mappings(mappings, options) mappings.each do |name, target_attribute| self.mappings << FlatMap::Mapping::Factory.new(name, target_attribute, options) end end