Class: Recliner::Associations::Reference

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id = nil) ⇒ Reference

Returns a new instance of Reference.



6
7
8
# File 'lib/recliner/associations/reference.rb', line 6

def initialize(id=nil)
  @id = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/recliner/associations/reference.rb', line 4

def id
  @id
end

Class Method Details

.from_couch(id) ⇒ Object



14
15
16
# File 'lib/recliner/associations/reference.rb', line 14

def self.from_couch(id)
  new(id)
end

.parse(id) ⇒ Object



18
19
20
# File 'lib/recliner/associations/reference.rb', line 18

def self.parse(id)
  new(id)
end

Instance Method Details

#==(other) ⇒ Object



10
11
12
# File 'lib/recliner/associations/reference.rb', line 10

def ==(other)
  other.is_a?(Reference) && id == other.id
end

#blank?Boolean

Returns:



26
27
28
# File 'lib/recliner/associations/reference.rb', line 26

def blank?
  id.blank?
end

#inspectObject



30
31
32
# File 'lib/recliner/associations/reference.rb', line 30

def inspect
  id.nil? ? 'nil' : id
end

#reloadObject



39
40
41
# File 'lib/recliner/associations/reference.rb', line 39

def reload
  @target = nil
end

#replace(object) ⇒ Object



34
35
36
37
# File 'lib/recliner/associations/reference.rb', line 34

def replace(object)
  @id = object.id
  @target = object
end

#targetObject



43
44
45
# File 'lib/recliner/associations/reference.rb', line 43

def target
  @target ||= Recliner::Document.load!(id) if id
end

#to_sObject



22
23
24
# File 'lib/recliner/associations/reference.rb', line 22

def to_s
  id.to_s
end