Class: Moped::BSON::Code
Overview
Object representation of a javascript expression.
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Class Method Summary collapse
-
.__bson_load__(io) ⇒ Code
Load the BSON from the raw data to a code.
Instance Method Summary collapse
-
#==(other) ⇒ true, false
(also: #eql?)
Check equality on the object.
-
#__bson_dump__(io, key) ⇒ Object
Dump the code into it’s raw bytes.
-
#hash ⇒ Fixnum
Gets the hash code for the object.
-
#initialize(code, scope = nil) ⇒ Code
constructor
Create the new code type.
-
#scoped? ⇒ true, false
Is the code scoped?.
Constructor Details
#initialize(code, scope = nil) ⇒ Code
Create the new code type.
76 77 78 79 |
# File 'lib/moped/bson/code.rb', line 76 def initialize(code, scope = nil) @code = code @scope = scope end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
7 8 9 |
# File 'lib/moped/bson/code.rb', line 7 def code @code end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
7 8 9 |
# File 'lib/moped/bson/code.rb', line 7 def scope @scope end |
Class Method Details
.__bson_load__(io) ⇒ Code
Load the BSON from the raw data to a code.
105 106 107 108 |
# File 'lib/moped/bson/code.rb', line 105 def __bson_load__(io) code = io.read(*io.read(4).unpack(INT32_PACK)).from_utf8_binary.chop! new(code) end |
Instance Method Details
#==(other) ⇒ true, false Also known as: eql?
Check equality on the object.
50 51 52 |
# File 'lib/moped/bson/code.rb', line 50 def ==(other) BSON::Code === other && code == other.code && scope == other.scope end |
#__bson_dump__(io, key) ⇒ Object
Dump the code into it’s raw bytes.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/moped/bson/code.rb', line 18 def __bson_dump__(io, key) if scoped? io << Types::CODE_WITH_SCOPE io << key.to_bson_cstring code_start = io.bytesize io << START_LENGTH data = code.to_utf8_binary io << [data.bytesize+1].pack(INT32_PACK) io << data io << NULL_BYTE scope.__bson_dump__(io) io[code_start, 4] = [io.bytesize - code_start].pack(INT32_PACK) else io << Types::CODE io << key.to_bson_cstring data = code.to_utf8_binary io << [data.bytesize+1].pack(INT32_PACK) io << data io << NULL_BYTE end end |
#hash ⇒ Fixnum
Gets the hash code for the object.
63 64 65 |
# File 'lib/moped/bson/code.rb', line 63 def hash [code, scope].hash end |
#scoped? ⇒ true, false
Is the code scoped?
89 90 91 |
# File 'lib/moped/bson/code.rb', line 89 def scoped? !!scope end |