Class: RDFMapper::Scope::Loader
- Inherits:
-
Object
- Object
- RDFMapper::Scope::Loader
- Defined in:
- lib/lib/scope/loader.rb
Overview
Loader is responsible for loading and updating model attributes. An instance of Loader is assigned to each search query and association.
Instance Method Summary collapse
-
#from(adapter_or_collection, options = {}) ⇒ Object
Sets data adapter or collection.
-
#get(index) ⇒ Object
Creates a new ‘scoped’ instance of RDFMapper::Model.
-
#has_id? ⇒ RDF::URI?
Checks if model ID is specified within conditions.
-
#initialize(cls, options = {}) ⇒ Loader
constructor
A new instance of Loader.
-
#inspect ⇒ String
Developer-friendly representation of the instance.
-
#length ⇒ Integer
Returns the number of loaded objects.
-
#update(index, instance = nil) ⇒ Object
Updates an existing ‘scoped’ instance of RDFMapper::Model (sets ID and attributes).
Constructor Details
Instance Method Details
#type(adapter, options = {}) ⇒ Object #type(collection) ⇒ Object
Sets data adapter or collection.
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/lib/scope/loader.rb', line 39 def from(adapter_or_collection, = {}) if adapter_or_collection.kind_of? Array @loaded = true 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, ) end |
#get(index) ⇒ Object
Creates a new ‘scoped’ instance of RDFMapper::Model.
67 68 69 70 |
# File 'lib/lib/scope/loader.rb', line 67 def get(index) instance = @cls.new(@objects[index]) RDFMapper::Scope.apply(instance, self, index) end |
#has_id? ⇒ RDF::URI?
Checks if model ID is specified within conditions. Returns RDF::URI if found, nil otherwise.
22 23 24 |
# File 'lib/lib/scope/loader.rb', line 22 def has_id? @conditions[:id].nil? ? nil : RDF::URI.new(@conditions[:id]) end |
#inspect ⇒ String
Developer-friendly representation of the instance
95 96 97 |
# File 'lib/lib/scope/loader.rb', line 95 def inspect #nodoc "#<%sLoader:%s>" % [@cls, object_id] end |
#length ⇒ Integer
Returns the number of loaded objects.
57 58 59 |
# File 'lib/lib/scope/loader.rb', line 57 def length load.length end |
#update(index, instance = nil) ⇒ Object
Updates an existing ‘scoped’ instance of RDFMapper::Model (sets ID and attributes).
80 81 82 83 84 85 86 87 88 |
# File 'lib/lib/scope/loader.rb', line 80 def update(index, instance = nil) #nodoc atts = load[index] if atts.nil? return instance.send(:nil!) end instance.send(:id=, atts[:id]) instance.attributes = atts instance end |