Class: Hiredis::Ruby::Reader::Task
- Inherits:
-
Object
- Object
- Hiredis::Ruby::Reader::Task
- Defined in:
- lib/hiredis/ruby/reader.rb
Constant Summary collapse
- METHOD_INDEX =
method_index.freeze
Instance Attribute Summary collapse
-
#depth ⇒ Object
readonly
Returns the value of attribute depth.
-
#multi_bulk ⇒ Object
Returns the value of attribute multi_bulk.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
-
#child ⇒ Object
Note: task depth is not checked.
-
#initialize(buffer, parent = nil, depth = 0) ⇒ Task
constructor
A new instance of Task.
- #process ⇒ Object
- #process_bulk_reply ⇒ Object
- #process_error_reply ⇒ Object
- #process_integer_reply ⇒ Object
- #process_multi_bulk_reply ⇒ Object
- #process_protocol_error ⇒ Object
- #process_status_reply ⇒ Object
- #reset! ⇒ Object
- #root ⇒ Object
Constructor Details
#initialize(buffer, parent = nil, depth = 0) ⇒ Task
Returns a new instance of Task.
39 40 41 |
# File 'lib/hiredis/ruby/reader.rb', line 39 def initialize(buffer, parent = nil, depth = 0) @buffer, @parent, @depth = buffer, parent, depth end |
Instance Attribute Details
#depth ⇒ Object (readonly)
Returns the value of attribute depth.
36 37 38 |
# File 'lib/hiredis/ruby/reader.rb', line 36 def depth @depth end |
#multi_bulk ⇒ Object
Returns the value of attribute multi_bulk.
37 38 39 |
# File 'lib/hiredis/ruby/reader.rb', line 37 def multi_bulk @multi_bulk end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
35 36 37 |
# File 'lib/hiredis/ruby/reader.rb', line 35 def parent @parent end |
Instance Method Details
#child ⇒ Object
Note: task depth is not checked.
44 45 46 |
# File 'lib/hiredis/ruby/reader.rb', line 44 def child @child ||= Task.new(@buffer, self, depth + 1) end |
#process ⇒ Object
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/hiredis/ruby/reader.rb', line 100 def process @line ||= @buffer.read_line return false if @line == false @type ||= @line.slice!(0) reply = send(METHOD_INDEX[@type] || :process_protocol_error) reset! if reply != false reply end |
#process_bulk_reply ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/hiredis/ruby/reader.rb', line 68 def process_bulk_reply bulk_length = @line.to_i return nil if bulk_length < 0 # Caught by caller function when false @buffer.read(bulk_length, 2) end |
#process_error_reply ⇒ Object
56 57 58 |
# File 'lib/hiredis/ruby/reader.rb', line 56 def process_error_reply RuntimeError.new(@line) end |
#process_integer_reply ⇒ Object
64 65 66 |
# File 'lib/hiredis/ruby/reader.rb', line 64 def process_integer_reply @line.to_i end |
#process_multi_bulk_reply ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/hiredis/ruby/reader.rb', line 76 def process_multi_bulk_reply multi_bulk_length = @line.to_i if multi_bulk_length > 0 @multi_bulk ||= [] # We know the multi bulk is not complete when this path is taken. while (element = child.process) != false @multi_bulk << element return @multi_bulk if @multi_bulk.length == multi_bulk_length end false elsif multi_bulk_length == 0 [] else nil end end |
#process_protocol_error ⇒ Object
96 97 98 |
# File 'lib/hiredis/ruby/reader.rb', line 96 def process_protocol_error raise "Protocol error" end |
#process_status_reply ⇒ Object
60 61 62 |
# File 'lib/hiredis/ruby/reader.rb', line 60 def process_status_reply @line end |
#reset! ⇒ Object
52 53 54 |
# File 'lib/hiredis/ruby/reader.rb', line 52 def reset! @line = @type = @multi_bulk = nil end |
#root ⇒ Object
48 49 50 |
# File 'lib/hiredis/ruby/reader.rb', line 48 def root parent ? parent.root : self end |