Class: Mongo::TopologyVersion Private

Inherits:
BSON::Document
  • Object
show all
Defined in:
build/ruby-driver-v2.19/lib/mongo/topology_version.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

TopologyVersion encapsulates the topologyVersion document obtained from hello responses and not master-like OperationFailure errors.

Instance Method Summary collapse

Constructor Details

#initialize(doc) ⇒ TopologyVersion

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of TopologyVersion.



24
25
26
27
28
29
30
31
32
33
34
35
# File 'build/ruby-driver-v2.19/lib/mongo/topology_version.rb', line 24

def initialize(doc)
  if Lint.enabled?
    unless doc['processId']
      raise ArgumentError, 'Creating a topology version without processId field'
    end
    unless doc['counter']
      raise ArgumentError, 'Creating a topology version without counter field'
    end
  end

  super
end

Instance Method Details

#counterInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The counter.

Returns:

  • (Integer)

    The counter.



43
44
45
# File 'build/ruby-driver-v2.19/lib/mongo/topology_version.rb', line 43

def counter
  self['counter']
end

#gt?(other) ⇒ true | false

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns whether this topology version is potentially newer than another topology version.

Note that there is no total ordering of topology versions - given two topology versions, each may be “potentially newer” than the other one.

Parameters:

Returns:

  • (true | false)

    Whether this topology version is potentially newer.



57
58
59
60
61
62
63
# File 'build/ruby-driver-v2.19/lib/mongo/topology_version.rb', line 57

def gt?(other)
  if process_id != other.process_id
    true
  else
    counter > other.counter
  end
end

#gte?(other) ⇒ true | false

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns whether this topology version is potentially newer than or equal to another topology version.

Note that there is no total ordering of topology versions - given two topology versions, each may be “potentially newer” than the other one.

Parameters:

Returns:

  • (true | false)

    Whether this topology version is potentially newer.



75
76
77
78
79
80
81
# File 'build/ruby-driver-v2.19/lib/mongo/topology_version.rb', line 75

def gte?(other)
  if process_id != other.process_id
    true
  else
    counter >= other.counter
  end
end

#process_idBSON::ObjectId

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The process id.

Returns:

  • (BSON::ObjectId)

    The process id.



38
39
40
# File 'build/ruby-driver-v2.19/lib/mongo/topology_version.rb', line 38

def process_id
  self['processId']
end

#to_docBSON::Document

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts the object to a document suitable for being sent to the server.

Returns:

  • (BSON::Document)

    The document.



88
89
90
# File 'build/ruby-driver-v2.19/lib/mongo/topology_version.rb', line 88

def to_doc
  BSON::Document.new(self).merge(counter: BSON::Int64.new(counter))
end