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

29
30
31
32
# File 'lib/bson/types/timestamp.rb', line 29

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

Instance Attribute Details

#incrementObject (readonly)

Returns the value of attribute increment


23
24
25
# File 'lib/bson/types/timestamp.rb', line 23

def increment
  @increment
end

#secondsObject (readonly)

Returns the value of attribute seconds


23
24
25
# File 'lib/bson/types/timestamp.rb', line 23

def seconds
  @seconds
end

Instance Method Details

#==(other) ⇒ Object


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

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.


48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/bson/types/timestamp.rb', line 48

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.


64
65
66
67
68
69
70
# File 'lib/bson/types/timestamp.rb', line 64

def each
  i = 0
  while i < 2
    yield self[i]
    i += 1
  end
end

#to_sObject


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

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