Class: Datamappify::Data::Criteria::Relational::Find

Inherits:
Common
  • Object
show all
Defined in:
lib/datamappify/data/criteria/relational/find.rb

Direct Known Subclasses

ActiveRecord::Find, FindByKey, Sequel::Find

Instance Attribute Summary

Attributes inherited from Common

#attributes, #attributes_and_values, #criteria, #entity, #options, #source_class

Instance Method Summary collapse

Methods inherited from Common

#any_attribute, #default_source_class_name, #ignore?, #ignore_attribute?, #initialize, #key_name, #key_value, #new_record?, #perform_with_callbacks, #pk, #primary_record?, #source_class_name, #store_attribute_value

Constructor Details

This class inherits a constructor from Datamappify::Data::Criteria::Common

Instance Method Details

#performObject



6
7
8
9
10
11
12
# File 'lib/datamappify/data/criteria/relational/find.rb', line 6

def perform
  record = source_class.where(criteria).first

  update_entity_with(record) if record

  record
end

#update_entity_with(record) ⇒ Object (private)



16
17
18
19
20
# File 'lib/datamappify/data/criteria/relational/find.rb', line 16

def update_entity_with(record)
  attributes.each do |attribute|
    entity.send("#{attribute.name}=", record.send(attribute.source_attribute_name))
  end
end