Class: Lafcadio::DomainObjectProxy

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from DomainComparable

#<=>, #eql?

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_classObject

Returns the value of attribute domain_class.



29
30
31
# File 'lib/lafcadio/objectStore.rb', line 29

def domain_class
  @domain_class
end

#pk_idObject

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_objectObject

: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

#hashObject

:nodoc:



57
58
59
# File 'lib/lafcadio/objectStore.rb', line 57

def hash #:nodoc:
	db_object.hash
end

#needs_refresh?Boolean

:nodoc:

Returns:

  • (Boolean)


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_sObject

:nodoc:



71
72
73
# File 'lib/lafcadio/objectStore.rb', line 71

def to_s #:nodoc:
	db_object.to_s
end