Class: Synapse::Mapping::Mapper
- Inherits:
-
Object
- Object
- Synapse::Mapping::Mapper
- Defined in:
- lib/synapse/mapping/mapper.rb
Instance Method Summary collapse
-
#each_type {|Class| ... } ⇒ undefined
Yields the type that each mapping is registered for.
- #initialize(duplicates_allowed) ⇒ undefined constructor
- #map(type, *args, &block) ⇒ undefined
-
#mapping_for(target_type) ⇒ Mapping
Retrieves the most specific mapping for a given type, if any.
Constructor Details
#initialize(duplicates_allowed) ⇒ undefined
6 7 8 9 |
# File 'lib/synapse/mapping/mapper.rb', line 6 def initialize(duplicates_allowed) @duplicates_allowed = duplicates_allowed @mappings = Array.new end |
Instance Method Details
#each_type {|Class| ... } ⇒ undefined
Yields the type that each mapping is registered for
15 16 17 18 19 |
# File 'lib/synapse/mapping/mapper.rb', line 15 def each_type @mappings.each do |mapping| yield mapping.type end end |
#map(type, *args, &block) ⇒ undefined
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/synapse/mapping/mapper.rb', line 27 def map(type, *args, &block) = args. mapping = create_from type, , &block unless @duplicates_allowed if @mappings.include? mapping raise DuplicateMappingError end end @mappings.push mapping @mappings.sort! end |
#mapping_for(target_type) ⇒ Mapping
Retrieves the most specific mapping for a given type, if any
45 46 47 48 49 |
# File 'lib/synapse/mapping/mapper.rb', line 45 def mapping_for(target_type) @mappings.find do |mapping| mapping.type >= target_type end end |