Class: Datamappify::Data::Criteria::Relational::FindMultiple
- Defined in:
- lib/datamappify/data/criteria/relational/find_multiple.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#primaries ⇒ Object
readonly
Returns the value of attribute primaries.
-
#secondaries ⇒ Object
readonly
Returns the value of attribute secondaries.
-
#structured_criteria ⇒ Object
readonly
Returns the value of attribute structured_criteria.
Attributes inherited from Common
#attributes, #attributes_and_values, #criteria, #entity, #options, #source_class
Instance Method Summary collapse
-
#data_record_for(attribute, primary_record) ⇒ Object
private
An ORM model object (ActiveRecord or Sequel, etc).
-
#initialize(*args) ⇒ FindMultiple
constructor
A new instance of FindMultiple.
- #perform ⇒ void
- #record_value_for(attribute, record) ⇒ any private
- #update_entity(entity, primary_record) ⇒ void private
- #updated_attributes ⇒ Array private
Methods inherited from Common
#any_attribute, #default_source_class_name, #ignore?, #ignore_attribute?, #key_name, #key_value, #new_record?, #perform_with_callbacks, #pk, #primary_record?, #store_attribute_value
Constructor Details
#initialize(*args) ⇒ FindMultiple
Returns a new instance of FindMultiple.
10 11 12 13 14 15 16 17 18 19 20 |
# 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 |
Instance Attribute Details
#primaries ⇒ Object (readonly)
Returns the value of attribute primaries.
8 9 10 |
# File 'lib/datamappify/data/criteria/relational/find_multiple.rb', line 8 def primaries @primaries end |
#secondaries ⇒ Object (readonly)
Returns the value of attribute secondaries.
8 9 10 |
# File 'lib/datamappify/data/criteria/relational/find_multiple.rb', line 8 def secondaries @secondaries end |
#structured_criteria ⇒ Object (readonly)
Returns the value of attribute structured_criteria.
8 9 10 |
# File 'lib/datamappify/data/criteria/relational/find_multiple.rb', line 8 def structured_criteria @structured_criteria end |
Instance Method Details
#data_record_for(attribute, primary_record) ⇒ Object (private)
Returns an ORM model object (ActiveRecord or Sequel, etc).
66 67 68 69 70 71 72 |
# 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 |
#perform ⇒ void
This method returns an undefined value.
23 24 25 26 27 28 29 |
# 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 |
#record_value_for(attribute, record) ⇒ any (private)
80 81 82 |
# 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) ⇒ void (private)
This method returns an undefined value.
50 51 52 53 54 55 56 57 |
# 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 ⇒ Array (private)
34 35 36 37 38 39 40 41 42 43 |
# 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 |