Class: KJess::Response

Inherits:
Protocol show all
Defined in:
lib/kjess/response.rb,
lib/kjess/response/end.rb,
lib/kjess/response/eof.rb,
lib/kjess/response/error.rb,
lib/kjess/response/stats.rb,
lib/kjess/response/value.rb,
lib/kjess/response/status.rb,
lib/kjess/response/stored.rb,
lib/kjess/response/deleted.rb,
lib/kjess/response/unknown.rb,
lib/kjess/response/version.rb,
lib/kjess/response/not_found.rb,
lib/kjess/response/not_stored.rb,
lib/kjess/response/client_error.rb,
lib/kjess/response/dumped_stats.rb,
lib/kjess/response/server_error.rb,
lib/kjess/response/reloaded_config.rb,
lib/kjess/response/flushed_all_queues.rb

Overview

Response is the parent class of all Response derived objects that come back from the Kestrel server. It holds the registry of all the Response objects and is responsible for parsing the initial line from the Kestrel server and determinig which Response child object to instantiate.

Defined Under Namespace

Classes: ClientError, Deleted, DumpedStats, End, Eof, Error, FlushedAllQueues, NotFound, NotStored, ReloadedConfig, ServerError, Stats, Status, Stored, Unknown, Value, Version

Constant Summary collapse

Registry =
Hash.new

Constants inherited from Protocol

Protocol::CRLF

Instance Attribute Summary

Attributes inherited from Protocol

#args, #raw_args

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Protocol

arity, #initialize, keyword, #keyword, register, #to_protocol

Constructor Details

This class inherits a constructor from KJess::Protocol

Class Method Details

.parse(str) ⇒ Object

Internal: parse the string and create the appropriate Response child object.

str - a String from the Kestrel server

Returns a new Response child object



20
21
22
23
24
# File 'lib/kjess/response.rb', line 20

def self.parse( str )
  keyword, *args = str.strip.split
  klass = Registry.fetch( keyword, KJess::Response::Unknown )
  klass.new( args )
end

.registryObject



10
11
12
# File 'lib/kjess/response.rb', line 10

def self.registry
  Registry
end

Instance Method Details

#error?Boolean

Internal: is this Response object an error object.

This is overwritte in those objects that create Exceptions

Returns false

Returns:

  • (Boolean)


55
56
57
# File 'lib/kjess/response.rb', line 55

def error?
  false
end

#messageObject

Internal: create the human readable version of this response

Returns a String



38
39
40
# File 'lib/kjess/response.rb', line 38

def message
  [ keyword, raw_args ].flatten.join(' ')
end

#parse_options_to_args(opts) ⇒ Object

Internal: callback to create the @args member

opts - the opts that were passed to initialize

Returns an Array



31
32
33
# File 'lib/kjess/response.rb', line 31

def parse_options_to_args( opts )
  [ opts ].flatten
end

#read_more(connection) ⇒ Object

Internal: callback that is used by some Responses that have more complex response creation.

connection - the KJess::Connection object to continue to read from

Returns nothing



48
# File 'lib/kjess/response.rb', line 48

def read_more( connection ); end