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

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

#attributesHash

In addition to the original method, preloads the model.

Returns:

  • (Hash)

    all attributes of an instance (name => value)



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'

Parameters:

  • adapter (Symbol)

    (:rails, :sparql, :rest)

  • options (Hash) (defaults to: {})

    options to pass on to the adapter constructor

Returns:

  • (self)


40
41
42
43
# File 'lib/lib/scope/model.rb', line 40

def from(adapter, options = {})
  @loader.from(adapter, options)
  self
end

#idObject

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

#inspectString

Developer-friendly representation of the instance.

Returns:

  • (String)


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.

Returns:

  • (Boolean)


77
78
79
# File 'lib/lib/scope/model.rb', line 77

def nil?
  @nil or (not @loaded and load.nil?)
end

#propertiesHash

In addition to the original method, preloads the model.

Returns:

  • (Hash)

    all attributes of an instance (name => value)



57
58
59
60
# File 'lib/lib/scope/model.rb', line 57

def properties
  check_for_nil_error
  @loaded ? super : load.properties
end