Class: Mongo::Server::AppMetadata::Truncator Private
- Inherits:
-
Object
- Object
- Mongo::Server::AppMetadata::Truncator
- Defined in:
- 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.
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.
512
Instance Attribute Summary collapse
-
#document ⇒ BSON::Document
readonly
private
The document being truncated.
Instance Method Summary collapse
-
#initialize(document) ⇒ Truncator
constructor
private
Creates a new Truncator instance and tries enforcing the maximum document size on the given document.
-
#ok? ⇒ true | false
private
Whether the document fits within the required maximum document size.
-
#size ⇒ Integer
private
The current size of the document, in bytes, as a serialized BSON document.
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.
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.
40 41 42 43 |
# File 'lib/mongo/server/app_metadata/truncator.rb', line 40 def initialize(document) @document = document try_truncate! end |
Instance Attribute Details
#document ⇒ BSON::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.
26 27 28 |
# File '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.
56 57 58 |
# File 'lib/mongo/server/app_metadata/truncator.rb', line 56 def ok? size <= MAX_DOCUMENT_SIZE end |
#size ⇒ Integer
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.
49 50 51 |
# File 'lib/mongo/server/app_metadata/truncator.rb', line 49 def size @document.to_bson.to_s.length end |