Class: Lafcadio::DomainObjectProxy
- Inherits:
-
Object
- Object
- Lafcadio::DomainObjectProxy
- Includes:
- DomainComparable
- Defined in:
- lib/lafcadio/objectStore/DomainObjectProxy.rb
Overview
The DomainObjectProxy is used when retrieving domain objects that are linked to other domain objects with LinkFields. In terms of objectType
and pkId
, a DomainObjectProxy instance looks to the outside world like the domain object it’s supposed to represent. It only retrieves its domain object from the database when member data is requested.
In normal usage you will probably never manipulate a DomainObjectProxy directly, but you may discover it by accident by calling DomainObjectProxy#class (or DomainObject#class) instead of DomainObjectProxy#objectType (or DomainObjectProxy#objectType).
Instance Attribute Summary collapse
-
#objectType ⇒ Object
Returns the value of attribute objectType.
-
#pkId ⇒ Object
Returns the value of attribute pkId.
Instance Method Summary collapse
- #getDbObject ⇒ Object
- #hash ⇒ Object
-
#initialize(objectTypeOrDbObject, pkId = nil) ⇒ DomainObjectProxy
constructor
A new instance of DomainObjectProxy.
- #method_missing(methodId, *args) ⇒ Object
- #needs_refresh? ⇒ Boolean
- #to_s ⇒ Object
Methods included from DomainComparable
Constructor Details
#initialize(objectTypeOrDbObject, pkId = nil) ⇒ DomainObjectProxy
Returns a new instance of DomainObjectProxy.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/lafcadio/objectStore/DomainObjectProxy.rb', line 19 def initialize(objectTypeOrDbObject, pkId = nil) if pkId @objectType = objectTypeOrDbObject @pkId = pkId elsif objectTypeOrDbObject.class < DomainObject @dbObject = objectTypeOrDbObject @d_obj_retrieve_time = Time.now @objectType = @dbObject.class @pkId = @dbObject.pkId else raise ArgumentError end @dbObject = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(methodId, *args) ⇒ Object
44 45 46 |
# File 'lib/lafcadio/objectStore/DomainObjectProxy.rb', line 44 def method_missing(methodId, *args) getDbObject.send(methodId.id2name, *args) end |
Instance Attribute Details
#objectType ⇒ Object
Returns the value of attribute objectType.
17 18 19 |
# File 'lib/lafcadio/objectStore/DomainObjectProxy.rb', line 17 def objectType @objectType end |
#pkId ⇒ Object
Returns the value of attribute pkId.
17 18 19 |
# File 'lib/lafcadio/objectStore/DomainObjectProxy.rb', line 17 def pkId @pkId end |
Instance Method Details
#getDbObject ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/lafcadio/objectStore/DomainObjectProxy.rb', line 34 def getDbObject object_store = ObjectStore.getObjectStore if @dbObject.nil? || needs_refresh? @dbObject = object_store.get(@objectType, @pkId) @d_obj_retrieve_time = Time.now end @dbObject end |
#hash ⇒ Object
58 59 60 |
# File 'lib/lafcadio/objectStore/DomainObjectProxy.rb', line 58 def hash getDbObject.hash end |
#needs_refresh? ⇒ Boolean
48 49 50 51 52 |
# File 'lib/lafcadio/objectStore/DomainObjectProxy.rb', line 48 def needs_refresh? object_store = ObjectStore.getObjectStore last_commit_time = object_store.last_commit_time( @objectType, @pkId ) !last_commit_time.nil? && last_commit_time > @d_obj_retrieve_time end |
#to_s ⇒ Object
54 55 56 |
# File 'lib/lafcadio/objectStore/DomainObjectProxy.rb', line 54 def to_s getDbObject.to_s end |