Class: Mongo::Protocol::CachingHash Private
- Inherits:
-
Object
- Object
- Mongo::Protocol::CachingHash
- Defined in:
- lib/mongo/protocol/caching_hash.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.
A Hash that caches the results of #to_bson.
Instance Method Summary collapse
- #bson_type ⇒ Object private
-
#initialize(hash) ⇒ CachingHash
constructor
private
A new instance of CachingHash.
-
#to_bson(buffer = BSON::ByteBuffer.new, validating_keys = nil) ⇒ BSON::ByteBuffer
private
Caches the result of to_bson and writes it to the given buffer on subsequent calls to this method.
Constructor Details
#initialize(hash) ⇒ CachingHash
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 CachingHash.
26 27 28 |
# File 'lib/mongo/protocol/caching_hash.rb', line 26 def initialize(hash) @hash = hash end |
Instance Method Details
#bson_type ⇒ Object
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.
30 31 32 |
# File 'lib/mongo/protocol/caching_hash.rb', line 30 def bson_type Hash::BSON_TYPE end |
#to_bson(buffer = BSON::ByteBuffer.new, validating_keys = nil) ⇒ BSON::ByteBuffer
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.
Caches the result of to_bson and writes it to the given buffer on subsequent calls to this method. If this method is originally called without validation, and then is subsequently called with validation, we will want to recalculate the to_bson to trigger the validations.
44 45 46 47 48 49 |
# File 'lib/mongo/protocol/caching_hash.rb', line 44 def to_bson(buffer = BSON::ByteBuffer.new, validating_keys = nil) if !@bytes @bytes = @hash.to_bson(BSON::ByteBuffer.new).to_s end buffer.put_bytes(@bytes) end |