Class: SdbDal::Reference
- Inherits:
-
Object
- Object
- SdbDal::Reference
- Defined in:
- lib/sdb_dal/reference.rb
Instance Attribute Summary collapse
-
#index ⇒ Object
Returns the value of attribute index.
-
#primary_key ⇒ Object
Returns the value of attribute primary_key.
-
#target_class ⇒ Object
Returns the value of attribute target_class.
Instance Method Summary collapse
- #get_target ⇒ Object
-
#initialize(options = {}) ⇒ Reference
constructor
A new instance of Reference.
- #targets?(item) ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Reference
Returns a new instance of Reference.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/sdb_dal/reference.rb', line 8 def initialize(={}) if .has_key?(:target) self.target_class=[:target].class.name.to_sym self.primary_key=[:target].primary_key end self.index=-1 if .has_key?(:index) self.index=[:index] end end |
Instance Attribute Details
#index ⇒ Object
Returns the value of attribute index.
7 8 9 |
# File 'lib/sdb_dal/reference.rb', line 7 def index @index end |
#primary_key ⇒ Object
Returns the value of attribute primary_key.
6 7 8 |
# File 'lib/sdb_dal/reference.rb', line 6 def primary_key @primary_key end |
#target_class ⇒ Object
Returns the value of attribute target_class.
5 6 7 |
# File 'lib/sdb_dal/reference.rb', line 5 def target_class @target_class end |
Instance Method Details
#get_target ⇒ Object
22 23 24 25 26 |
# File 'lib/sdb_dal/reference.rb', line 22 def get_target the_class=Kernel.const_get(self.target_class) the_class.find(self.primary_key) end |
#targets?(item) ⇒ Boolean
18 19 20 21 |
# File 'lib/sdb_dal/reference.rb', line 18 def targets?(item) return false unless item self.target_class==item.class.name.to_sym and self.primary_key==item.primary_key end |