Class: Datamappify::Data::Mapper
- Inherits:
-
Object
- Object
- Datamappify::Data::Mapper
- Defined in:
- lib/datamappify/data/mapper.rb,
lib/datamappify/data/mapper/attribute.rb
Defined Under Namespace
Classes: Attribute
Instance Attribute Summary collapse
-
#custom_mapping ⇒ Hash
Attribute name to source mapping as specified in Repository::MappingDSL#map_attribute.
- #default_provider_name ⇒ String
- #default_source_class_name ⇒ String
- #entity_class ⇒ Class
Instance Method Summary collapse
- #all_attribute_names ⇒ Array<Symbol> private
- #attributes ⇒ Set<Attribute>
-
#classified_attributes ⇒ Hash<Set>
Attribute sets classified by the names of their data provider.
- #custom_attribute_names ⇒ Array<Symbol> private
- #custom_attributes ⇒ Array<Attribute> private
- #default_attribute_names ⇒ Array<Symbol> private
- #default_attributes ⇒ Array<Attribute> private
- #default_provider ⇒ Module
- #default_source_class ⇒ Class
- #default_source_for(attribute) ⇒ String private
-
#initialize ⇒ Mapper
constructor
A new instance of Mapper.
- #map_custom_attribute(name, source, options) ⇒ Attribute private
- #provider(provider_name) ⇒ Module
Constructor Details
#initialize ⇒ Mapper
Returns a new instance of Mapper.
20 21 22 23 |
# File 'lib/datamappify/data/mapper.rb', line 20 def initialize @custom_mapping = {} @custom_attribute_names = [] end |
Instance Attribute Details
#custom_mapping ⇒ Hash
Returns attribute name to source mapping as specified in Repository::MappingDSL#map_attribute.
18 19 20 |
# File 'lib/datamappify/data/mapper.rb', line 18 def custom_mapping @custom_mapping end |
#default_provider_name ⇒ String
11 12 13 |
# File 'lib/datamappify/data/mapper.rb', line 11 def default_provider_name @default_provider_name end |
#default_source_class_name ⇒ String
43 44 45 |
# File 'lib/datamappify/data/mapper.rb', line 43 def default_source_class_name @default_source_class_name ||= entity_class.name end |
#entity_class ⇒ Class
8 9 10 |
# File 'lib/datamappify/data/mapper.rb', line 8 def entity_class @entity_class end |
Instance Method Details
#all_attribute_names ⇒ Array<Symbol> (private)
61 62 63 |
# File 'lib/datamappify/data/mapper.rb', line 61 def all_attribute_names entity_class.attribute_set.entries.collect(&:name) end |
#attributes ⇒ Set<Attribute>
48 49 50 |
# File 'lib/datamappify/data/mapper.rb', line 48 def attributes @attributes ||= Set.new(default_attributes + custom_attributes) end |
#classified_attributes ⇒ Hash<Set>
Returns attribute sets classified by the names of their data provider.
54 55 56 |
# File 'lib/datamappify/data/mapper.rb', line 54 def classified_attributes @classified_attributes ||= Set.new(attributes).classify(&:provider_name) end |
#custom_attribute_names ⇒ Array<Symbol> (private)
71 72 73 74 75 76 |
# File 'lib/datamappify/data/mapper.rb', line 71 def custom_attribute_names # make sure custom attributes are always processed custom_attributes @custom_attribute_names end |
#custom_attributes ⇒ Array<Attribute> (private)
86 87 88 89 90 |
# File 'lib/datamappify/data/mapper.rb', line 86 def custom_attributes @custom_attributes ||= custom_mapping.collect do |attribute, | map_custom_attribute(attribute, *) end end |
#default_attribute_names ⇒ Array<Symbol> (private)
66 67 68 |
# File 'lib/datamappify/data/mapper.rb', line 66 def default_attribute_names all_attribute_names - custom_attribute_names end |
#default_attributes ⇒ Array<Attribute> (private)
79 80 81 82 83 |
# File 'lib/datamappify/data/mapper.rb', line 79 def default_attributes @default_attributes ||= default_attribute_names.collect do |attribute| Attribute.new(attribute, default_source_for(attribute), :primary_source_class => default_source_class) end end |
#default_provider ⇒ Module
26 27 28 |
# File 'lib/datamappify/data/mapper.rb', line 26 def default_provider @default_provider ||= Provider.const_get(default_provider_name) end |
#default_source_class ⇒ Class
38 39 40 |
# File 'lib/datamappify/data/mapper.rb', line 38 def default_source_class @default_source_class ||= default_provider.find_or_build_record_class(default_source_class_name) end |
#default_source_for(attribute) ⇒ String (private)
107 108 109 |
# File 'lib/datamappify/data/mapper.rb', line 107 def default_source_for(attribute) "#{default_provider_name}::#{default_source_class_name}##{attribute}" end |
#map_custom_attribute(name, source, options) ⇒ Attribute (private)
95 96 97 98 99 100 101 |
# File 'lib/datamappify/data/mapper.rb', line 95 def map_custom_attribute(name, source, ) @custom_attribute_names << name .merge!(:primary_source_class => default_source_class) Attribute.new(name, source, ) end |
#provider(provider_name) ⇒ Module
33 34 35 |
# File 'lib/datamappify/data/mapper.rb', line 33 def provider(provider_name) Provider.const_get(provider_name) end |