class Hiredis::Ruby::Reader::Task

Constants

METHOD_INDEX

Attributes

depth[R]
multi_bulk[RW]
parent[R]

Public Class Methods

new(buffer, parent = nil, depth = 0) click to toggle source
# File lib/hiredis/ruby/reader.rb, line 39
def initialize(buffer, parent = nil, depth = 0)
  @buffer, @parent, @depth = buffer, parent, depth
end

Public Instance Methods

child() click to toggle source

Note: task depth is not checked.

# File lib/hiredis/ruby/reader.rb, line 44
def child
  @child ||= Task.new(@buffer, self, depth + 1)
end
process() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/hiredis/ruby/reader.rb, line 56
def process_error_reply
  RuntimeError.new(@line)
end
process_integer_reply() click to toggle source
# File lib/hiredis/ruby/reader.rb, line 64
def process_integer_reply
  @line.to_i
end
process_multi_bulk_reply() click to toggle source
# 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() click to toggle source
# File lib/hiredis/ruby/reader.rb, line 96
def process_protocol_error
  raise "Protocol error"
end
process_status_reply() click to toggle source
# File lib/hiredis/ruby/reader.rb, line 60
def process_status_reply
  @line
end
reset!() click to toggle source
# File lib/hiredis/ruby/reader.rb, line 52
def reset!
  @line = @type = @multi_bulk = nil
end
root() click to toggle source
# File lib/hiredis/ruby/reader.rb, line 48
def root
  parent ? parent.root : self
end