class Mongo::TopologyVersion

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

@api private

Public Class Methods

new(doc) click to toggle source
Calls superclass method
# File lib/mongo/topology_version.rb, line 23
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

Public Instance Methods

counter() click to toggle source

@return [ Integer ] The counter.

# File lib/mongo/topology_version.rb, line 42
def counter
  self['counter']
end
gt?(other) click to toggle source

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.

@param [ TopologyVersion ] other The other topology version.

@return [ true | false ] Whether this topology version is potentially newer. @api private

# File lib/mongo/topology_version.rb, line 56
def gt?(other)
  if process_id != other.process_id
    true
  else
    counter > other.counter
  end
end
gte?(other) click to toggle source

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.

@param [ TopologyVersion ] other The other topology version.

@return [ true | false ] Whether this topology version is potentially newer. @api private

# File lib/mongo/topology_version.rb, line 74
def gte?(other)
  if process_id != other.process_id
    true
  else
    counter >= other.counter
  end
end
process_id() click to toggle source

@return [ BSON::ObjectId ] The process id.

# File lib/mongo/topology_version.rb, line 37
def process_id
  self['processId']
end
to_doc() click to toggle source

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

@return [ BSON::Document ] The document.

@api private

# File lib/mongo/topology_version.rb, line 87
def to_doc
  BSON::Document.new(self).merge(counter: BSON::Int64.new(counter))
end