Module: Mongo::DBRef::ClassMethods

Defined in:
build/ruby-driver-master/lib/mongo/dbref.rb

Overview

Since:

  • 2.1.0

Instance Method Summary collapse

Instance Method Details

#from_bson(buffer, **options) ⇒ Hash, DBRef

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

Parameters:

  • buffer (String)

    The bson representing a hash.

Returns:

  • (Hash, DBRef)

    The decoded hash or DBRef.

See Also:

Since:

  • 2.0.0



106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'build/ruby-driver-master/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