Class: BSON::Timestamp
- Inherits:
-
Object
- Object
- BSON::Timestamp
- Includes:
- Enumerable
- Defined in:
- lib/bson/types/timestamp.rb
Overview
A class for representing BSON Timestamps. The Timestamp type is used by MongoDB internally; thus, it should be used by application developers for diagnostic purposes only.
Instance Attribute Summary collapse
-
#increment ⇒ Object
readonly
Returns the value of attribute increment.
-
#seconds ⇒ Object
readonly
Returns the value of attribute seconds.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](index) ⇒ Object deprecated Deprecated.
- #each ⇒ Object deprecated Deprecated.
-
#initialize(seconds, increment) ⇒ Timestamp
constructor
Create a new BSON Timestamp.
- #to_s ⇒ Object
Constructor Details
#initialize(seconds, increment) ⇒ Timestamp
Create a new BSON Timestamp.
33 34 35 36 |
# File 'lib/bson/types/timestamp.rb', line 33 def initialize(seconds, increment) @seconds = seconds @increment = increment end |
Instance Attribute Details
#increment ⇒ Object (readonly)
Returns the value of attribute increment.
27 28 29 |
# File 'lib/bson/types/timestamp.rb', line 27 def increment @increment end |
#seconds ⇒ Object (readonly)
Returns the value of attribute seconds.
27 28 29 |
# File 'lib/bson/types/timestamp.rb', line 27 def seconds @seconds end |
Instance Method Details
#==(other) ⇒ Object
42 43 44 45 |
# File 'lib/bson/types/timestamp.rb', line 42 def ==(other) self.seconds == other.seconds && self.increment == other.increment end |
#[](index) ⇒ Object
Deprecated.
This is for backward-compatibility. Timestamps in the Ruby driver used to deserialize as arrays. So we provide an equivalent interface.
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/bson/types/timestamp.rb', line 52 def [](index) warn "Timestamps are no longer deserialized as arrays. If you're working " + "with BSON Timestamp objects, see the BSON::Timestamp class. This usage will " + "be deprecated in Ruby Driver v2.0." if index == 0 self.increment elsif index == 1 self.seconds else nil end end |
#each ⇒ Object
Deprecated.
This method exists only for backward-compatibility.
68 69 70 71 72 73 74 |
# File 'lib/bson/types/timestamp.rb', line 68 def each i = 0 while i < 2 yield self[i] i += 1 end end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/bson/types/timestamp.rb', line 38 def to_s "seconds: #{seconds}, increment: #{increment}" end |