Class: BSON::Timestamp
Overview
Represents a timestamp type, which is predominately used for sharding.
Constant Summary collapse
- BSON_TYPE =
A timestamp is type 0x11 in the BSON spec.
17.chr.force_encoding(BINARY).freeze
Instance Attribute Summary collapse
- #increment ⇒ Object
-
#seconds ⇒ Integer
The number of seconds.
Class Method Summary collapse
-
.from_bson(bson) ⇒ Timestamp
Deserialize timestamp from BSON.
Instance Method Summary collapse
-
#==(other) ⇒ true, false
Determine if this timestamp is equal to another object.
-
#as_json(*args) ⇒ Hash
Get the timestamp as JSON hash data.
-
#initialize(seconds, increment) ⇒ Timestamp
constructor
Instantiate the new timestamp.
-
#to_bson(encoded = ''.force_encoding(BINARY)) ⇒ String
Get the timestamp as its encoded raw BSON bytes.
Methods included from JSON
Constructor Details
#initialize(seconds, increment) ⇒ Timestamp
Instantiate the new timestamp.
76 77 78 |
# File 'lib/bson/timestamp.rb', line 76 def initialize(seconds, increment) @seconds, @increment = seconds, increment end |
Instance Attribute Details
#seconds ⇒ Integer
Returns The number of seconds.
38 39 40 |
# File 'lib/bson/timestamp.rb', line 38 def seconds @seconds end |
Class Method Details
Instance Method Details
#==(other) ⇒ true, false
Determine if this timestamp is equal to another object.
50 51 52 53 |
# File 'lib/bson/timestamp.rb', line 50 def ==(other) return false unless other.is_a?(Timestamp) seconds == other.seconds && increment == other.increment end |
#as_json(*args) ⇒ Hash
Get the timestamp as JSON hash data.
63 64 65 |
# File 'lib/bson/timestamp.rb', line 63 def as_json(*args) { "t" => seconds, "i" => increment } end |