Class: ApiResource::Finders::SingleFinder

Inherits:
AbstractFinder show all
Defined in:
lib/api_resource/finders/single_finder.rb

Instance Attribute Summary

Attributes inherited from AbstractFinder

#condition, #found, #internal_object, #klass

Instance Method Summary collapse

Methods inherited from AbstractFinder

#all, #headers, #initialize, #instance_of?, #is_a?, #kind_of?, #method_missing, #offset, #paginated?, #response, #total_entries

Constructor Details

This class inherits a constructor from ApiResource::Finders::AbstractFinder

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ApiResource::Finders::AbstractFinder

Instance Method Details

#loadObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/api_resource/finders/single_finder.rb', line 7

def load
  return nil if self.response.blank?

  @loaded = true

  @internal_object = self.klass.instantiate_record(self.response)
  # now that the object is loaded, resolve the includes
  id_hash = self.condition.included_objects.inject({}) do |hash, assoc|
    hash[assoc] = Array.wrap(
      @internal_object.send(
        @internal_object.class.association_foreign_key_field(assoc)
      )
    )
    hash
  end

  included_objects = self.load_includes(id_hash)

  self.apply_includes(@internal_object, included_objects)

  return @internal_object
end