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
-
#child ⇒ Object
Returns the value of attribute child.
-
#multi_bulk ⇒ Object
Returns the value of attribute multi_bulk.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
-
#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.
38 39 40 41 42 43 |
# File 'lib/hiredis/ruby/reader.rb', line 38 def initialize(buffer, parent = nil, depth = 0) @buffer, @parent = buffer, parent # Require 3 nested tasks @child = Task.new(@buffer, self, depth + 1) if depth < 2 end |
Instance Attribute Details
#child ⇒ Object
Returns the value of attribute child.
35 36 37 |
# File 'lib/hiredis/ruby/reader.rb', line 35 def child @child end |
#multi_bulk ⇒ Object
Returns the value of attribute multi_bulk.
36 37 38 |
# File 'lib/hiredis/ruby/reader.rb', line 36 def multi_bulk @multi_bulk end |
#parent ⇒ Object
Returns the value of attribute parent.
35 36 37 |
# File 'lib/hiredis/ruby/reader.rb', line 35 def parent @parent end |
Instance Method Details
#process ⇒ Object
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/hiredis/ruby/reader.rb', line 97 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
65 66 67 68 69 70 71 |
# File 'lib/hiredis/ruby/reader.rb', line 65 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
53 54 55 |
# File 'lib/hiredis/ruby/reader.rb', line 53 def process_error_reply RuntimeError.new(@line) end |
#process_integer_reply ⇒ Object
61 62 63 |
# File 'lib/hiredis/ruby/reader.rb', line 61 def process_integer_reply @line.to_i end |
#process_multi_bulk_reply ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/hiredis/ruby/reader.rb', line 73 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
93 94 95 |
# File 'lib/hiredis/ruby/reader.rb', line 93 def process_protocol_error raise "Protocol error" end |
#process_status_reply ⇒ Object
57 58 59 |
# File 'lib/hiredis/ruby/reader.rb', line 57 def process_status_reply @line end |
#reset! ⇒ Object
49 50 51 |
# File 'lib/hiredis/ruby/reader.rb', line 49 def reset! @line = @type = @multi_bulk = nil end |
#root ⇒ Object
45 46 47 |
# File 'lib/hiredis/ruby/reader.rb', line 45 def root parent ? parent.root : self end |