Module: RDFMapper::Scope::Model
- Defined in:
- lib/lib/scope/model.rb
Overview
Extension of RDFMapper::Model that implements lazy-loading. All models in collections and search queries will implement this module by default.
Instance Method Summary collapse
-
#[](name) ⇒ Object
In addition to the original method, preloads the model.
-
#attributes ⇒ Hash
In addition to the original method, preloads the model.
-
#from(adapter, options = {}) ⇒ self
Set data adapter for the query and return self.
-
#id ⇒ Object
Returns instance’s unique ID (as RDF::URI).
-
#inspect ⇒ String
Developer-friendly representation of the instance.
-
#nil? ⇒ Boolean
Checks if the instance is ‘nil`.
-
#properties ⇒ Hash
In addition to the original method, preloads the model.
Instance Method Details
#[](name) ⇒ Object
In addition to the original method, preloads the model.
48 49 50 |
# File 'lib/lib/scope/model.rb', line 48 def [](name) @arbitrary[name] || (@loaded ? super(name) : load[name]) end |
#attributes ⇒ Hash
In addition to the original method, preloads the model.
67 68 69 70 |
# File 'lib/lib/scope/model.rb', line 67 def attributes check_for_nil_error @loaded ? super : load.attributes end |
#from(adapter, options = {}) ⇒ self
Set data adapter for the query and return self. This will override the default model adapter. It is intended to be used as a chain method:
Person.find(:first).from(:rails) #=> #<Person:217132856>
Person.find(:first).from(:rails).name #=> 'John'
40 41 42 43 |
# File 'lib/lib/scope/model.rb', line 40 def from(adapter, = {}) @loader.from(adapter, ) self end |
#id ⇒ Object
Returns instance’s unique ID (as RDF::URI).
24 25 26 |
# File 'lib/lib/scope/model.rb', line 24 def id super || @loader.has_id? || load.id end |
#inspect ⇒ String
Developer-friendly representation of the instance.
86 87 88 |
# File 'lib/lib/scope/model.rb', line 86 def inspect #nodoc "#<Scoped|%s:%s>" % [self.class, object_id] end |
#nil? ⇒ Boolean
Checks if the instance is ‘nil`. Will load the instance to find it out.
77 78 79 |
# File 'lib/lib/scope/model.rb', line 77 def nil? @nil or (not @loaded and load.nil?) end |
#properties ⇒ Hash
In addition to the original method, preloads the model.
57 58 59 60 |
# File 'lib/lib/scope/model.rb', line 57 def properties check_for_nil_error @loaded ? super : load.properties end |