Module: BSON::Hash::ClassMethods

Defined in:
lib/bson/hash.rb

Overview

The methods to augment the Hash class with (class-level methods).

Instance Method Summary collapse

Instance Method Details

#from_bson(buffer, **options) ⇒ Hash

Note:

If the argument cannot be parsed, an exception will be raised and the argument will be left in an undefined state. The caller must explicitly call rewind on the buffer before trying to parse it again.

Deserialize the hash from BSON.

Parameters:

  • buffer (ByteBuffer)

    The byte buffer.

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • :mode (nil | :bson)

    Decoding mode to use.

Returns:

  • (Hash)

    The decoded hash.

See Also:



137
138
139
140
141
142
143
144
# File 'lib/bson/hash.rb', line 137

def from_bson(buffer, **options)
  if buffer.respond_to?(:get_hash)
    buffer.get_hash(**options)
  else
    hash = parse_hash_from_buffer(buffer, **options)
    maybe_dbref(hash)
  end
end