Class: Moped::BSON::Code
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
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #__bson_dump__(io, key) ⇒ Object
- #hash ⇒ Object
-
#initialize(code, scope = nil) ⇒ Code
constructor
A new instance of Code.
- #scoped? ⇒ Boolean
Constructor Details
#initialize(code, scope = nil) ⇒ Code
Returns a new instance of Code.
7 8 9 10 |
# File 'lib/moped/bson/code.rb', line 7 def initialize(code, scope=nil) @code = code @scope = scope end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
5 6 7 |
# File 'lib/moped/bson/code.rb', line 5 def code @code end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
5 6 7 |
# File 'lib/moped/bson/code.rb', line 5 def scope @scope end |
Class Method Details
.__bson_load__(io) ⇒ Object
26 27 28 29 |
# File 'lib/moped/bson/code.rb', line 26 def __bson_load__(io) code = io.read(*io.read(4).unpack(INT32_PACK)).from_utf8_binary.chop! new code end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
16 17 18 |
# File 'lib/moped/bson/code.rb', line 16 def ==(other) BSON::Code === other && code == other.code && scope == other.scope end |
#__bson_dump__(io, key) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/moped/bson/code.rb', line 32 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 ⇒ Object
21 22 23 |
# File 'lib/moped/bson/code.rb', line 21 def hash [code, scope].hash end |
#scoped? ⇒ Boolean
12 13 14 |
# File 'lib/moped/bson/code.rb', line 12 def scoped? !!scope end |