Class: Lafcadio::DomainObjectProxy
- Inherits:
-
Object
- Object
- Lafcadio::DomainObjectProxy
- Includes:
- DomainComparable
- Defined in:
- lib/lafcadio/objectStore.rb
Overview
The DomainObjectProxy is used when retrieving domain objects that are linked to other domain objects with DomainObjectFields. In terms of domain_class
and pk_id
, 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#domain_class (or DomainObjectProxy#domain_class).
Instance Attribute Summary collapse
-
#domain_class ⇒ Object
Returns the value of attribute domain_class.
-
#pk_id ⇒ Object
Returns the value of attribute pk_id.
Instance Method Summary collapse
-
#db_object ⇒ Object
:nodoc:.
- #db_object=(dbo) ⇒ Object
-
#hash ⇒ Object
:nodoc:.
-
#initialize(*args) ⇒ DomainObjectProxy
constructor
:nodoc:.
-
#method_missing(methodId, *args) ⇒ Object
:nodoc:.
-
#needs_refresh? ⇒ Boolean
:nodoc:.
-
#to_s ⇒ Object
:nodoc:.
Methods included from DomainComparable
Constructor Details
#initialize(*args) ⇒ DomainObjectProxy
:nodoc:
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/lafcadio/objectStore.rb', line 31 def initialize( *args ) #:nodoc: if args.size == 2 @domain_class = args.first @pk_id = args.last elsif args.first.is_a?( DomainObject ) @d_obj_retrieve_time = Time.now @domain_class = args.first.class @pk_id = args.first.pk_id else raise ArgumentError end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(methodId, *args) ⇒ Object
:nodoc:
61 62 63 |
# File 'lib/lafcadio/objectStore.rb', line 61 def method_missing( methodId, *args ) #:nodoc: db_object.send( methodId, *args ) end |
Instance Attribute Details
#domain_class ⇒ Object
Returns the value of attribute domain_class.
29 30 31 |
# File 'lib/lafcadio/objectStore.rb', line 29 def domain_class @domain_class end |
#pk_id ⇒ Object
Returns the value of attribute pk_id.
29 30 31 |
# File 'lib/lafcadio/objectStore.rb', line 29 def pk_id @pk_id end |
Instance Method Details
#db_object ⇒ Object
:nodoc:
44 45 46 47 48 49 50 |
# File 'lib/lafcadio/objectStore.rb', line 44 def db_object #:nodoc: if @db_object.nil? || needs_refresh? dbo = ObjectStore.get_object_store.get( @domain_class, @pk_id ) self.db_object = dbo end @db_object end |
#db_object=(dbo) ⇒ Object
52 53 54 55 |
# File 'lib/lafcadio/objectStore.rb', line 52 def db_object=( dbo ) @db_object = dbo @d_obj_retrieve_time = Time.now end |
#hash ⇒ Object
:nodoc:
57 58 59 |
# File 'lib/lafcadio/objectStore.rb', line 57 def hash #:nodoc: db_object.hash end |
#needs_refresh? ⇒ Boolean
:nodoc:
65 66 67 68 69 |
# File 'lib/lafcadio/objectStore.rb', line 65 def needs_refresh? #:nodoc: object_store = ObjectStore.get_object_store last_commit_time = object_store.last_commit_time( @domain_class, @pk_id ) last_commit_time && last_commit_time > @d_obj_retrieve_time end |
#to_s ⇒ Object
:nodoc:
71 72 73 |
# File 'lib/lafcadio/objectStore.rb', line 71 def to_s #:nodoc: db_object.to_s end |