Class: SdbDal::Reference

Inherits:
Object
  • Object
show all
Defined in:
lib/sdb_dal/reference.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options={})
    if options.has_key?(:target)
        self.target_class=options[:target].class.name.to_sym
        self.primary_key=options[:target].primary_key
    end
    self.index=-1
    if options.has_key?(:index)
        self.index=options[:index]
    end
end

Instance Attribute Details

#indexObject

Returns the value of attribute index.



7
8
9
# File 'lib/sdb_dal/reference.rb', line 7

def index
  @index
end

#primary_keyObject

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_classObject

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_targetObject



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

Returns:

  • (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