class Datamappify::Data::Mapper
Attributes
custom_mapping[RW]
@return [Hash]
attribute name to source mapping as specified in {Repository::MappingDSL#map_attribute}
default_provider_name[RW]
@return [String]
default_source_class_name[W]
@return [String]
entity_class[RW]
@return [Class]
Public Class Methods
new()
click to toggle source
# File lib/datamappify/data/mapper.rb, line 20 def initialize @custom_mapping = {} @custom_attribute_names = [] @default_provider_name = Datamappify.defaults.default_provider end
Public Instance Methods
attributes()
click to toggle source
@return [Set<Attribute>]
# File lib/datamappify/data/mapper.rb, line 50 def attributes @attributes ||= Set.new(default_attributes + custom_attributes) end
classified_attributes()
click to toggle source
@return [Hash<Set>]
attribute sets classified by the names of their data provider
# File lib/datamappify/data/mapper.rb, line 56 def classified_attributes @classified_attributes ||= Set.new(attributes).classify(&:provider_name) end
default_provider()
click to toggle source
@return [Module]
# File lib/datamappify/data/mapper.rb, line 28 def default_provider @default_provider ||= Provider.const_get(default_provider_name) end
default_source_class()
click to toggle source
@return [Class]
# File lib/datamappify/data/mapper.rb, line 40 def default_source_class @default_source_class ||= default_provider.find_or_build_record_class(default_source_class_name) end
default_source_class_name()
click to toggle source
@return [String]
# File lib/datamappify/data/mapper.rb, line 45 def default_source_class_name @default_source_class_name ||= entity_class.name end
provider(provider_name)
click to toggle source
@param provider_name [String]
@return [Module]
# File lib/datamappify/data/mapper.rb, line 35 def provider(provider_name) Provider.const_get(provider_name) end
Private Instance Methods
all_attribute_names()
click to toggle source
@return [Array<Symbol>]
# File lib/datamappify/data/mapper.rb, line 63 def all_attribute_names entity_class.attribute_set.entries.collect(&:name) end
custom_attribute_names()
click to toggle source
@return [Array<Symbol>]
# File lib/datamappify/data/mapper.rb, line 73 def custom_attribute_names # make sure custom attributes are always processed custom_attributes @custom_attribute_names end
custom_attributes()
click to toggle source
@return [Array<Attribute>]
# File lib/datamappify/data/mapper.rb, line 93 def custom_attributes @custom_attributes ||= custom_mapping.collect do |attribute, options| map_custom_attribute(attribute, options) end end
default_attribute_names()
click to toggle source
@return [Array<Symbol>]
# File lib/datamappify/data/mapper.rb, line 68 def default_attribute_names all_attribute_names - custom_attribute_names end
default_attributes()
click to toggle source
@return [Array<Attribute>]
# File lib/datamappify/data/mapper.rb, line 81 def default_attributes @default_attributes ||= default_attribute_names.collect do |attribute| Attribute.new( attribute, :to => default_source_for(attribute), :provider => default_provider_name, :primary_source_class => default_source_class ) end end
default_source_for(attribute)
click to toggle source
@param attribute [Symbol]
name of the attribute
@return [String]
# File lib/datamappify/data/mapper.rb, line 115 def default_source_for(attribute) "#{default_source_class_name}##{attribute}" end
map_custom_attribute(name, options)
click to toggle source
@param (see Data::Mapper::Attribute#initialize)
@return [Attribute]
# File lib/datamappify/data/mapper.rb, line 102 def map_custom_attribute(name, options) @custom_attribute_names << name options.reverse_merge!(:provider => default_provider_name) options.merge!(:primary_source_class => default_source_class) Attribute.new(name, options) end