Class: SimpleAttributeMapper::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_attribute_mapper/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



3
4
5
# File 'lib/simple_attribute_mapper/configuration.rb', line 3

def initialize
  @maps = []
end

Instance Attribute Details

#mapsObject (readonly)

Returns the value of attribute maps.



7
8
9
# File 'lib/simple_attribute_mapper/configuration.rb', line 7

def maps
  @maps
end

Instance Method Details

#<<(map) ⇒ Object



19
20
21
# File 'lib/simple_attribute_mapper/configuration.rb', line 19

def << map
  add_mapping(map)
end

#add_mapping(map) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/simple_attribute_mapper/configuration.rb', line 9

def add_mapping(map)
  maps.each do |existing_map|
    if existing_map.source_class == map.source_class && existing_map.target_class == map.target_class
      raise DuplicateMappingError.new("Map is already configured for '#{map.source_class}' -> '#{map.target_class}'")
    end
  end

  maps << map
end

#clearObject

for testing only



30
31
32
# File 'lib/simple_attribute_mapper/configuration.rb', line 30

def clear
  @maps = []
end

#find_mapping(source_class, target_class) ⇒ Object



23
24
25
26
27
# File 'lib/simple_attribute_mapper/configuration.rb', line 23

def find_mapping(source_class, target_class)
  maps.select do |map|
    map.source_class == source_class && map.target_class == target_class
  end
end