Skip to content

Commit

Permalink
Loader now accepts collections as data source (in addition to adapters)
Browse files Browse the repository at this point in the history
  • Loading branch information
serebryakov committed May 28, 2010
1 parent 1b0599b commit 6b5a25d
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions lib/lib/scope/loader.rb
Expand Up @@ -24,14 +24,29 @@ def has_id?
end end


## ##
# Sets data adapter for this loader. This will override default model adapter. # Sets data adapter or collection.
# #
# @param [Symbol] adapter (:rails, :sparql, :rest) # @overload type(adapter, options = {})
# @param [Hash] options options to pass on to the adapter constructor # Sets data adapter, this will override default model adapter
# @return [Object] adapter instance # @param [Symbol] adapter (:rails, :sparql, :rest)
## # @param [Hash] options options to pass on to the adapter constructor
def from(adapter, options = {}) # @return [Object] adapter instance
@adapter = RDFMapper::Adapters.register(adapter, @cls, options) #
# @overload type(collection)
# Sets collection of instances that should be queried.
# @param [Array] collection
##
def from(adapter_or_collection, options = {})
if adapter_or_collection.kind_of? Array
@loaded = true
@objects = adapter_or_collection.select do |instance|
@conditions.matches?(instance)
end.each do |instance|
@objects << instance.properties
end
return
end
@adapter = RDFMapper::Adapters.register(adapter_or_collection, @cls, options)
end end


## ##
Expand Down

0 comments on commit 6b5a25d

Please sign in to comment.