Class: OskieRpc::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/oskie_rpc/processor.rb

Instance Method Summary collapse

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

Raises:



28
29
30
31
32
33
# File 'lib/oskie_rpc/processor.rb', line 28

def deliver(message)
  raise InvalidStateError unless @state == :initialized
  @output_chain << message.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