module BSON::Object

Injects behaviour for all Ruby objects.

@since 2.2.4

Public Instance Methods

as_extended_json(**options) click to toggle source

Converts this object to a representation directly serializable to Extended JSON (github.com/mongodb/specifications/blob/master/source/extended-json.rst).

Subclasses should override this method to provide custom serialization to Extended JSON.

@option options [ true | false ] :relaxed Whether to produce relaxed

extended JSON representation.

@return [ Object ] The extended json representation.

# File lib/bson/object.rb, line 86
def as_extended_json(**options)
  self
end
to_bson_key(validating_keys = Config.validating_keys?) click to toggle source

Objects that don’t override this method will raise an error when trying to use them as keys in a BSON document. This is only overridden in String and Symbol.

@example Convert the object to a BSON key.

object.to_bson_key

@raise [ InvalidKey ] Always raises an exception.

@see bsonspec.org/#/specification

@since 2.2.4

# File lib/bson/object.rb, line 35
def to_bson_key(validating_keys = Config.validating_keys?)
  raise InvalidKey.new(self)
end
to_bson_normalized_key() click to toggle source

Converts the object to a normalized key in a BSON document.

@example Convert the object to a normalized key.

object.to_bson_normalized_key

@return [ Object ] self.

@since 3.0.0

# File lib/bson/object.rb, line 47
def to_bson_normalized_key
  self
end
to_bson_normalized_value() click to toggle source

Converts the object to a normalized value in a BSON document.

@example Convert the object to a normalized value.

object.to_bson_normalized_value

@return [ Object ] self.

@since 3.0.0

# File lib/bson/object.rb, line 59
def to_bson_normalized_value
  self
end
to_extended_json(**options) click to toggle source

Serializes this object to Extended JSON (github.com/mongodb/specifications/blob/master/source/extended-json.rst).

Subclasses should override as_extended_json rather than this method.

@option opts [ nil | :relaxed | :legacy ] :mode Serialization mode

(default is canonical extended JSON)

@return [ String ] The extended json serialization.

# File lib/bson/object.rb, line 72
def to_extended_json(**options)
  as_extended_json(**options).to_json
end