module Mongo::DBRef::ClassMethods

Public Instance Methods

from_bson(buffer, **options) click to toggle source

Deserialize the hash from BSON, converting to a DBRef if appropriate.

@param [ String ] buffer The bson representing a hash.

@return [ Hash, DBRef ] The decoded hash or DBRef.

@see bsonspec.org/#/specification

@since 2.0.0

Calls superclass method
# File lib/mongo/dbref.rb, line 106
def from_bson(buffer, **options)
  # bson-ruby 4.8.0 changes #from_bson API to take **options.
  # However older bsons fail if invoked with a plain super here,
  # even if options are empty.
  decoded = if options.empty?
    super(buffer)
  else
    super
  end
  if ref = decoded[COLLECTION]
    decoded = DBRef.new(ref, decoded[ID], decoded[DATABASE])
  end
  decoded
end