Class: OskieRpc::Processor
- Inherits:
-
Object
- Object
- OskieRpc::Processor
- Defined in:
- lib/oskie_rpc/processor.rb
Instance Method Summary collapse
- #<<(bytes) ⇒ Object
- #deliver(message) ⇒ Object
-
#initialize(opts = {}, &block) ⇒ Processor
constructor
A new instance of Processor.
- #on(name, &block) ⇒ Object
Constructor Details
#initialize(opts = {}, &block) ⇒ Processor
Returns a new instance of Processor.
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/oskie_rpc/processor.rb', line 3 def initialize(opts = {}, &block) @opts = opts @lock = Mutex.new @input_chain = create_input_chain @output_chain = create_output_chain @callbacks = {} @state = :initializing block.call(self) if block raise MissingCallbackError, :message unless @callbacks[:message] raise MissingCallbackError, :output unless @callbacks[:output] @state = :initialized end |
Instance Method Details
#<<(bytes) ⇒ Object
16 17 18 19 20 |
# File 'lib/oskie_rpc/processor.rb', line 16 def <<(bytes) @input_chain << bytes nil end |
#deliver(message) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/oskie_rpc/processor.rb', line 28 def deliver() raise InvalidStateError unless @state == :initialized @output_chain << .to_hash nil end |
#on(name, &block) ⇒ Object
22 23 24 25 26 |
# File 'lib/oskie_rpc/processor.rb', line 22 def on(name, &block) @callbacks[name.to_sym] = block nil end |