Class: KJess::Protocol
- Inherits:
-
Object
- Object
- KJess::Protocol
- Defined in:
- lib/kjess/protocol.rb
Overview
Protocol is the base class that all Kestrel requests and responses are developed on. it defines the DSL for creating the Request and Response objects that make up the Protocol.
Constant Summary collapse
- CRLF =
"\r\n"
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#raw_args ⇒ Object
readonly
Returns the value of attribute raw_args.
Class Method Summary collapse
-
.arity(a = nil) ⇒ Object
Internal: define or return the arity of this protocol item.
-
.keyword(name = nil) ⇒ Object
Internal: The keyword that starts this protocol message.
-
.register(name) ⇒ Object
Internal: register this protocol item with its registry.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Protocol
constructor
A new instance of Protocol.
-
#keyword ⇒ Object
Internal: return the keyword.
-
#parse_options_to_args(opts) ⇒ Object
Internal: callback that child classes may use to further parse the initialization arguments.
-
#to_protocol ⇒ Object
Internal: Convert the object to its protocol serialized format.
Constructor Details
#initialize(opts = {}) ⇒ Protocol
Returns a new instance of Protocol.
48 49 50 51 |
# File 'lib/kjess/protocol.rb', line 48 def initialize( opts = {} ) @raw_args = opts @args = ( opts ) || [] end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
45 46 47 |
# File 'lib/kjess/protocol.rb', line 45 def args @args end |
#raw_args ⇒ Object (readonly)
Returns the value of attribute raw_args.
46 47 48 |
# File 'lib/kjess/protocol.rb', line 46 def raw_args @raw_args end |
Class Method Details
.arity(a = nil) ⇒ Object
Internal: define or return the arity of this protocol item
arity - the number of args this protocol item has
Returns the arity
30 31 32 33 |
# File 'lib/kjess/protocol.rb', line 30 def arity( a = nil ) @arity = a if a @arity end |
.keyword(name = nil) ⇒ Object
Internal: The keyword that starts this protocol message
name - the keyword to define this portion of the protocol
Returns the name
16 17 18 19 20 21 22 23 |
# File 'lib/kjess/protocol.rb', line 16 def keyword( name = nil ) @keyword = nil unless defined? @keyword if name then register( name ) @keyword = name end @keyword ||= nil end |
.register(name) ⇒ Object
Internal: register this protocol item with its registry
name - the name under which to register the protocol
Returns nothing
40 41 42 |
# File 'lib/kjess/protocol.rb', line 40 def register( name ) registry[name] ||= self end |
Instance Method Details
#keyword ⇒ Object
Internal: return the keyword
Returns a String
73 74 75 |
# File 'lib/kjess/protocol.rb', line 73 def keyword self.class.keyword end |
#parse_options_to_args(opts) ⇒ Object
Internal: callback that child classes may use to further parse the initialization arguments
Returns Array
57 |
# File 'lib/kjess/protocol.rb', line 57 def ( opts ); end |
#to_protocol ⇒ Object
Internal: Convert the object to its protocol serialized format.
This may be overridden in child classes
Return a String
64 65 66 67 68 |
# File 'lib/kjess/protocol.rb', line 64 def to_protocol s = keyword s += " #{args.join(' ')}" unless args.empty? s += CRLF end |