module BSON::Symbol
Injects behaviour for encoding and decoding symbol values to and from raw bytes as specified by the BSON
spec.
@note Symbols are deprecated in the BSON
spec, but they are still
currently supported here for backwards compatibility.
@see bsonspec.org/#/specification
@since 2.0.0
Constants
- BSON_TYPE
-
A symbol is type 0x0E in the
BSON
spec.@since 2.0.0
Public Instance Methods
Source
# File lib/bson/symbol.rb, line 100 def as_extended_json(**options) { "$symbol" => to_s } end
Converts this object to a representation directly serializable to Extended JSON
(github.com/mongodb/specifications/blob/master/source/extended-json.rst).
@option options [ true | false ] :relaxed Whether to produce relaxed
extended JSON representation.
@return [ Hash
] The extended json representation.
Source
# File lib/bson/symbol.rb, line 46 def bson_type String::BSON_TYPE end
Symbols are serialized as strings as symbols are now removed from the BSON
specification. Therefore the bson_type
when serializing must be a string.
@example Get the BSON
type for the symbol.
:test.bson_type
@return [ String
] The single byte BSON
type.
@see bsonspec.org/#/specification
@since 4.0.0
Source
# File lib/bson/symbol.rb, line 60 def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?) buffer.put_symbol(self) end
Get the symbol as encoded BSON
.
@example Get the symbol as encoded BSON
.
:test.to_bson
@return [ BSON::ByteBuffer
] The buffer with the encoded object.
@see bsonspec.org/#/specification
@since 2.0.0
Source
# File lib/bson/symbol.rb, line 74 def to_bson_key(validating_keys = Config.validating_keys?) if validating_keys raise BSON::String::IllegalKey.new(self) if BSON::String::ILLEGAL_KEY =~ self end self end
Get the symbol as a BSON
key name encoded C symbol.
@example Get the symbol as a key name.
:test.to_bson_key
@return [ String
] The encoded symbol as a BSON
key.
@see bsonspec.org/#/specification
@since 2.0.0