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, #initialize, #method_missing

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
	data = self.klass.connection.get(self.build_load_path)

	@loaded = true
	return nil if data.blank?
	@internal_object = self.klass.instantiate_record(data)
	# now that the object is loaded, resolve the includes
	id_hash = self.condition.included_objects.inject({}) do |accum, assoc|
		accum[assoc] = Array.wrap(
			@internal_object.send(
				@internal_object.class.association_foreign_key_field(assoc)
			)
		)
		accum
	end

	included_objects = self.load_includes(id_hash)

	self.apply_includes(@internal_object, included_objects)

	return @internal_object
end