Class: BSON::Timestamp

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(seconds, increment) ⇒ Timestamp

Create a new BSON Timestamp.

Parameters:

  • seconds (Integer)

    The number of seconds

  • increment


33
34
35
36
# File 'lib/bson/types/timestamp.rb', line 33

def initialize(seconds, increment)
  @seconds   = seconds
  @increment = increment
end

Instance Attribute Details

#incrementObject (readonly)

Returns the value of attribute increment.



27
28
29
# File 'lib/bson/types/timestamp.rb', line 27

def increment
  @increment
end

#secondsObject (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

#eachObject

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_sObject



38
39
40
# File 'lib/bson/types/timestamp.rb', line 38

def to_s
  "seconds: #{seconds}, increment: #{increment}"
end