class BSON::DbPointer
@see bsonspec.org/#/specification<br><br>raw bytes as specified by the BSON spec.
Injects behaviour for encoding and decoding DBPointer values to and from
def self.from_bson(buffer, **options)
- See: http://bsonspec.org/#/specification -
Returns:
-
(BSON::DbPointer)
- The decoded DBPointer.
Options Hash:
(**options)
-
:mode
(nil | :bson
) -- Decoding mode to use.
Parameters:
-
options
(Hash
) -- -
buffer
(ByteBuffer
) -- The byte buffer.
def self.from_bson(buffer, **options) ref = buffer.get_string id = if options.empty? ObjectId.from_bson(buffer) else ObjectId.from_bson(buffer, **options) end new(ref, id) end
def ==(other)
-
(true | false)
- If the objects are equal
Parameters:
-
other
(Object
) -- The object to compare against.
def ==(other) return false unless other.is_a?(DbPointer) ref == other.ref && id == other.id end
def as_extended_json(**_options)
-
(Hash)
- The extended json representation.
def as_extended_json(**_options) { '$dbPointer' => { "$ref" => ref, '$id' => id.as_extended_json } } end
def as_json(*_args)
-
(Hash)
- The extended json representation.
def as_json(*_args) as_extended_json end
def initialize(ref, id)
-
id
(BSON::ObjectId
) -- The DBPointer id. -
ref
(String
) -- The database collection name.
def initialize(ref, id) @ref = ref @id = id end
def to_bson(buffer = ByteBuffer.new)
- See: http://bsonspec.org/#/specification -
Returns:
-
(BSON::ByteBuffer)
- The buffer with the encoded object.
def to_bson(buffer = ByteBuffer.new) buffer.put_string(ref) id.to_bson(buffer) buffer end