Class: Recliner::Associations::Reference
- Defined in:
- lib/recliner/associations/reference.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #blank? ⇒ Boolean
-
#initialize(id = nil) ⇒ Reference
constructor
A new instance of Reference.
- #inspect ⇒ Object
- #reload ⇒ Object
- #replace(object) ⇒ Object
- #target ⇒ Object
- #to_s ⇒ Object
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
#id ⇒ Object (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
26 27 28 |
# File 'lib/recliner/associations/reference.rb', line 26 def blank? id.blank? end |
#inspect ⇒ Object
30 31 32 |
# File 'lib/recliner/associations/reference.rb', line 30 def inspect id.nil? ? 'nil' : id end |
#reload ⇒ Object
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 |
#target ⇒ Object
43 44 45 |
# File 'lib/recliner/associations/reference.rb', line 43 def target @target ||= Recliner::Document.load!(id) if id end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/recliner/associations/reference.rb', line 22 def to_s id.to_s end |