class Datamappify::Data::Criteria::Relational::FindMultiple
Attributes
primaries[R]
secondaries[R]
structured_criteria[R]
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
Datamappify::Data::Criteria::Common::new
# File lib/datamappify/data/criteria/relational/find_multiple.rb, line 10 def initialize(*args) super @primaries = [] @secondaries = [] updated_attributes.each do |attribute| collector = attribute.primary_attribute? ? @primaries : @secondaries collector << attribute end end
Public Instance Methods
perform()
click to toggle source
@return [void]
# File lib/datamappify/data/criteria/relational/find_multiple.rb, line 23 def perform records.map do |record| entity = entity_class.new update_entity(entity, record) entity end end
Private Instance Methods
data_record_for(attribute, primary_record)
click to toggle source
@param attribute [Attribute]
@param primary_record [Class]
an ORM model object (ActiveRecord or Sequel, etc)
@return [Object]
an ORM model object (ActiveRecord or Sequel, etc)
# File lib/datamappify/data/criteria/relational/find_multiple.rb, line 66 def data_record_for(attribute, primary_record) if attribute.primary_attribute? primary_record else primary_record.send(attribute.source_key) end end
record_value_for(attribute, record)
click to toggle source
@param attribute [Attribute]
@param record [Class]
an ORM model object (ActiveRecord or Sequel, etc)
@return [any]
# File lib/datamappify/data/criteria/relational/find_multiple.rb, line 80 def record_value_for(attribute, record) record.nil? ? nil : record.send(attribute.source_attribute_name) end
update_entity(entity, primary_record)
click to toggle source
@param entity [Entity]
@param record [Class]
@return [void]
# File lib/datamappify/data/criteria/relational/find_multiple.rb, line 50 def update_entity(entity, primary_record) attributes.each do |attribute| record = data_record_for(attribute, primary_record) value = record_value_for(attribute, record) entity.send("#{attribute.name}=", value) end end
updated_attributes()
click to toggle source
@return [Array]
# File lib/datamappify/data/criteria/relational/find_multiple.rb, line 34 def updated_attributes unless criteria.keys & attributes.map(&:key) == criteria.keys raise EntityAttributeInvalid end @updated_attributes ||= attributes.select do |attribute| attribute.value = criteria[attribute.key] criteria.keys.include?(attribute.key) end end