Class: MongoModel::Reference
- Inherits:
-
Object
- Object
- MongoModel::Reference
- Defined in:
- lib/mongomodel/support/reference.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
- #blank? ⇒ Boolean
- #eql?(other) ⇒ Boolean (also: #==)
- #hash ⇒ Object
-
#initialize(id) ⇒ Reference
constructor
A new instance of Reference.
- #to_mongo ⇒ Object
- #to_s ⇒ Object (also: #to_str)
Constructor Details
#initialize(id) ⇒ Reference
Returns a new instance of Reference.
5 6 7 |
# File 'lib/mongomodel/support/reference.rb', line 5 def initialize(id) @id = id end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/mongomodel/support/reference.rb', line 3 def id @id end |
Class Method Details
.cast(value) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/mongomodel/support/reference.rb', line 41 def self.cast(value) case value when BSON::ObjectId new(value) else if BSON::ObjectId.legal?(value.to_s) new(BSON::ObjectId(value.to_s)) else new(value.to_s) end end end |
.from_mongo(value) ⇒ Object
54 55 56 |
# File 'lib/mongomodel/support/reference.rb', line 54 def self.from_mongo(value) cast(value) end |
Instance Method Details
#as_json ⇒ Object
19 20 21 |
# File 'lib/mongomodel/support/reference.rb', line 19 def as_json(*) to_s end |
#blank? ⇒ Boolean
23 24 25 |
# File 'lib/mongomodel/support/reference.rb', line 23 def blank? id.blank? end |
#eql?(other) ⇒ Boolean Also known as: ==
27 28 29 30 31 32 33 34 |
# File 'lib/mongomodel/support/reference.rb', line 27 def eql?(other) case other when Reference id.to_s == other.id.to_s else id.to_s == other.to_s end end |
#hash ⇒ Object
15 16 17 |
# File 'lib/mongomodel/support/reference.rb', line 15 def hash id.hash end |
#to_mongo ⇒ Object
37 38 39 |
# File 'lib/mongomodel/support/reference.rb', line 37 def to_mongo id.blank? ? nil : id end |
#to_s ⇒ Object Also known as: to_str
9 10 11 |
# File 'lib/mongomodel/support/reference.rb', line 9 def to_s id.to_s end |