Sha256: 3d92809d4bfacdf5abcacda6cf01a05f10c2763b429b2e1e3ecde8656dbd3b39

Contents?: true

Size: 1.14 KB

Versions: 16

Compression:

Stored size: 1.14 KB

Contents

module ApiResource

	module Finders

		class ResourceFinder < AbstractFinder

			# this is a little bit simpler, it's always a collection and does
			# not require a remote path
			def load
				begin
					@loaded = true
					@internal_object = self.klass.connection.get(self.build_load_path)
					return [] if @internal_object.blank?

					@internal_object = self.klass.instantiate_collection(@internal_object)

					id_hash = self.condition.included_objects.inject({}) do |accum, assoc|
						accum[assoc] = @internal_object.collect do |obj|
							obj.send(self.klass.association_foreign_key_field(assoc))
						end
						accum[assoc].flatten!
						accum[assoc].uniq!
						accum
					end
					included_objects = self.load_includes(id_hash)

					self.apply_includes(@internal_object, included_objects)

					return @internal_object
				rescue ApiResource::ResourceNotFound
					nil
				end
				@internal_object
			end

			protected


        # Find every resource
        def build_load_path
        	prefix_opts, query_opts = self.klass.split_options(self.condition.to_hash)
	        self.klass.collection_path(prefix_opts, query_opts)
        end

		end

	end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
api_resource-0.6.16 lib/api_resource/finders/resource_finder.rb
api_resource-0.6.15 lib/api_resource/finders/resource_finder.rb
api_resource-0.6.14 lib/api_resource/finders/resource_finder.rb
api_resource-0.6.13 lib/api_resource/finders/resource_finder.rb
api_resource-0.6.12 lib/api_resource/finders/resource_finder.rb
api_resource-0.6.11 lib/api_resource/finders/resource_finder.rb
api_resource-0.6.9 lib/api_resource/finders/resource_finder.rb
api_resource-0.6.10 lib/api_resource/finders/resource_finder.rb
api_resource-0.6.8 lib/api_resource/finders/resource_finder.rb
api_resource-0.6.7 lib/api_resource/finders/resource_finder.rb
api_resource-0.6.6 lib/api_resource/finders/resource_finder.rb
api_resource-0.6.5 lib/api_resource/finders/resource_finder.rb
api_resource-0.6.4 lib/api_resource/finders/resource_finder.rb
api_resource-0.6.3 lib/api_resource/finders/resource_finder.rb
api_resource-0.6.2 lib/api_resource/finders/resource_finder.rb
api_resource-0.6.1 lib/api_resource/finders/resource_finder.rb