class Rumid::Request
Abstract class, representing Request
. Should be extended to specify protocol. @abstract @example
class Foo < Request read_wire do |io| io.readline end format_request do |raw| {route: raw[1], data: raw[2]} end validate_request do |raw| raw[4] != raw[5] end validate_request do |raw| raw[1]+raw[2] != raw[3] end end
Public Class Methods
format_request(&block)
click to toggle source
Initialize raw data to request hash parser @param block [Proc] representing raw data to request hash parser @note block requires requires [String] raw data
# File lib/rumid/request.rb, line 47 def self.format_request(&block) @@wire_parser = block end
read_wire(&block)
click to toggle source
validate_request(&block)
click to toggle source
Initialize new request validator @param block [Proc] represent request validator @note Proc requires [Stirng] raw data @note Proc returns [Boolean] request validness
# File lib/rumid/request.rb, line 64 def self.validate_request(&block) @@request_validators << block end
Public Instance Methods
get_request(io)
click to toggle source
Method gets only valid requests @param io [IO] representing raw data to request hash parser @note Typicaly you should not call this method
# File lib/rumid/request.rb, line 54 def get_request(io) raw = @@wire_handler.call(io) throw NotValidRequestError if @@request_validators.all?{|block| block.call(raw)} @@wire_parser.call(raw) end