Module: SimpleAttributeMapper
- Defined in:
- lib/simple_attribute_mapper.rb,
lib/simple_attribute_mapper/map.rb,
lib/simple_attribute_mapper/mapper.rb,
lib/simple_attribute_mapper/version.rb,
lib/simple_attribute_mapper/configuration.rb,
lib/simple_attribute_mapper/un_mappable_error.rb,
lib/simple_attribute_mapper/configuration_error.rb,
lib/simple_attribute_mapper/duplicate_mapping_error.rb
Defined Under Namespace
Classes: Configuration, ConfigurationError, DuplicateMappingError, Map, Mapper, UnMappableError
Constant Summary
collapse
- VERSION =
"0.0.3"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
11
12
13
|
# File 'lib/simple_attribute_mapper.rb', line 11
def configuration
@configuration
end
|
Class Method Details
14
15
16
17
|
# File 'lib/simple_attribute_mapper.rb', line 14
def self.configure
self.configuration ||= Configuration.new
yield(configuration)
end
|
.from(source_class) ⇒ Object
19
20
21
|
# File 'lib/simple_attribute_mapper.rb', line 19
def self.from(source_class)
Map.new(source_class)
end
|
.map(source_instance, target_class) ⇒ Object
23
24
25
|
# File 'lib/simple_attribute_mapper.rb', line 23
def self.map(source_instance, target_class)
mapper_for(source_instance, target_class).map(source_instance, target_class)
end
|
.map_attributes(source_instance, target_instance) ⇒ Object
27
28
29
|
# File 'lib/simple_attribute_mapper.rb', line 27
def self.map_attributes(source_instance, target_instance)
mapper_for(source_instance, target_instance.class).map_attributes(source_instance, target_instance)
end
|
.mapper_for(source_instance, target_class) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/simple_attribute_mapper.rb', line 31
def self.mapper_for(source_instance, target_class)
if self.configuration.maps.length == 0
raise ConfigurationError.new("There are no mappings configured, check the documentation for configuration steps")
end
mappings = configuration.find_mapping(source_instance.class, target_class)
if mappings.length == 0
raise ConfigurationError.new("There are no mappings configured for '#{source_instance.class}' -> '#{target_class}'")
end
Mapper.new(mappings[0].mappings)
end
|