Class: BSON::Code
Overview
Represents a code type, which is a wrapper around javascript code.
Constant Summary collapse
- BSON_TYPE =
A code is type 0x0D in the BSON spec.
13.chr.force_encoding(BINARY).freeze
Instance Attribute Summary collapse
Class Method Summary collapse
-
.from_bson(buffer) ⇒ TrueClass, FalseClass
Deserialize code from BSON.
Instance Method Summary collapse
-
#==(other) ⇒ true, false
Determine if this code object is equal to another object.
-
#as_json(*args) ⇒ Hash
Get the code as JSON hash data.
-
#initialize(javascript = "") ⇒ Code
constructor
Instantiate the new code.
-
#to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?) ⇒ String
Encode the javascript code.
Methods included from JSON
Constructor Details
#initialize(javascript = "") ⇒ Code
Instantiate the new code.
70 71 72 |
# File 'lib/bson/code.rb', line 70 def initialize(javascript = "") @javascript = javascript end |
Instance Attribute Details
Class Method Details
.from_bson(buffer) ⇒ TrueClass, FalseClass
Deserialize code from BSON.
97 98 99 |
# File 'lib/bson/code.rb', line 97 def self.from_bson(buffer) new(buffer.get_string) end |
Instance Method Details
#==(other) ⇒ true, false
Determine if this code object is equal to another object.
45 46 47 48 |
# File 'lib/bson/code.rb', line 45 def ==(other) return false unless other.is_a?(Code) javascript == other.javascript end |
#as_json(*args) ⇒ Hash
Get the code as JSON hash data.
58 59 60 |
# File 'lib/bson/code.rb', line 58 def as_json(*args) { "$code" => javascript } end |
#to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?) ⇒ String
Encode the javascript code.
84 85 86 |
# File 'lib/bson/code.rb', line 84 def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?) buffer.put_string(javascript) # @todo: was formerly to_bson_string end |