Class: Mongo::Server::AppMetadata::Truncator Private

Inherits:
Object
  • Object
show all
Defined in:
build/ruby-driver-v2.19/lib/mongo/server/app_metadata/truncator.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.

Implements the metadata truncation logic described in the handshake spec.

Since:

  • 2.0.0

Constant Summary collapse

MAX_DOCUMENT_SIZE =

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

The max application metadata document byte size.

Since:

  • 2.0.0

512

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ Truncator

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.

Note:

The document is modified in-place; if you wish to keep the original unchanged, you must deep-clone it prior to sending it to a truncator.

Creates a new Truncator instance and tries enforcing the maximum document size on the given document.

Parameters:

  • document (BSON::Document)

    The document to (potentially) truncate.

Since:

  • 2.0.0



40
41
42
43
# File 'build/ruby-driver-v2.19/lib/mongo/server/app_metadata/truncator.rb', line 40

def initialize(document)
  @document = document
  try_truncate!
end

Instance Attribute Details

#documentBSON::Document (readonly)

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 document being truncated.

Returns:

  • (BSON::Document)

    the document being truncated.

Since:

  • 2.0.0



26
27
28
# File 'build/ruby-driver-v2.19/lib/mongo/server/app_metadata/truncator.rb', line 26

def document
  @document
end

Instance Method Details

#ok?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.

Whether the document fits within the required maximum document size.

Returns:

  • (true | false)

    if the document is okay or not.

Since:

  • 2.0.0



56
57
58
# File 'build/ruby-driver-v2.19/lib/mongo/server/app_metadata/truncator.rb', line 56

def ok?
  size <= MAX_DOCUMENT_SIZE
end

#sizeInteger

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.

The current size of the document, in bytes, as a serialized BSON document.

Returns:

  • (Integer)

    the size of the document

Since:

  • 2.0.0



49
50
51
# File 'build/ruby-driver-v2.19/lib/mongo/server/app_metadata/truncator.rb', line 49

def size
  @document.to_bson.to_s.length
end