Skip to content
Browse files

Loader now accepts collections as data source (in addition to adapters)

  • Loading branch information...
1 parent 1b0599b commit 6b5a25d2424a40f05c3b604d5d1d41a9b3cce817 @serebryakov serebryakov committed May 28, 2010
Showing with 22 additions and 7 deletions.
  1. +22 −7 lib/lib/scope/loader.rb
View
29 lib/lib/scope/loader.rb
@@ -24,14 +24,29 @@ def has_id?
end
##
- # Sets data adapter for this loader. This will override default model adapter.
+ # Sets data adapter or collection.
#
- # @param [Symbol] adapter (:rails, :sparql, :rest)
- # @param [Hash] options options to pass on to the adapter constructor
- # @return [Object] adapter instance
- ##
- def from(adapter, options = {})
- @adapter = RDFMapper::Adapters.register(adapter, @cls, options)
+ # @overload type(adapter, options = {})
+ # Sets data adapter, this will override default model adapter
+ # @param [Symbol] adapter (:rails, :sparql, :rest)
+ # @param [Hash] options options to pass on to the adapter constructor
+ # @return [Object] adapter instance
+ #
+ # @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
##

0 comments on commit 6b5a25d

Please sign in to comment.
Something went wrong with that request. Please try again.