Module: BSON::Symbol
- Defined in:
- lib/bson/symbol.rb
Overview
Symbols are deprecated in the BSON spec, but they are still currently supported here for backwards compatibility.
Injects behaviour for encoding and decoding symbol values to and from raw bytes as specified by the BSON spec.
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- BSON_TYPE =
A symbol is type 0x0E in the BSON spec.
14.chr.force_encoding(BINARY).freeze
Instance Method Summary collapse
-
#bson_type ⇒ String
Symbols are serialized as strings as symbols are now removed from the BSON specification.
-
#to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?) ⇒ Symbol
Get the symbol as encoded BSON.
-
#to_bson_key(validating_keys = Config.validating_keys?) ⇒ String
Get the symbol as a BSON key name encoded C symbol.
-
#to_bson_normalized_key ⇒ String
Converts the symbol to a normalized key in a BSON document.
Instance Method Details
#bson_type ⇒ String
Symbols are serialized as strings as symbols are now removed from the BSON specification. Therefore the bson_type when serializing must be a string.
45 46 47 |
# File 'lib/bson/symbol.rb', line 45 def bson_type String::BSON_TYPE end |
#to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?) ⇒ Symbol
Get the symbol as encoded BSON.
59 60 61 |
# File 'lib/bson/symbol.rb', line 59 def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?) to_s.to_bson(buffer) end |
#to_bson_key(validating_keys = Config.validating_keys?) ⇒ String
Get the symbol as a BSON key name encoded C symbol.
73 74 75 |
# File 'lib/bson/symbol.rb', line 73 def to_bson_key(validating_keys = Config.validating_keys?) to_s.to_bson_key(validating_keys) end |
#to_bson_normalized_key ⇒ String
Converts the symbol to a normalized key in a BSON document.
85 86 87 |
# File 'lib/bson/symbol.rb', line 85 def to_bson_normalized_key to_s end |