Class: Citrus::Common::Service::HandlerService

Inherits:
Object
  • Object
show all
Defined in:
lib/citrus/common/service/handler_service.rb

Overview

HandlerService

Instance Method Summary collapse

Constructor Details

#initialize(app, handlers = {}) ⇒ HandlerService

Initialize the service

Parameters:

  • app (Object)
  • handlers (Hash) (defaults to: {})


22
23
24
25
# File 'lib/citrus/common/service/handler_service.rb', line 22

def initialize app, handlers={}
  @app = app
  @handlers = handlers
end

Instance Method Details

#handle(route_record, msg, session, &block) ⇒ Object

Handle message from the client

Parameters:

  • route_record (Hash)
  • msg (Hash)
  • session (Object)


32
33
34
35
36
37
38
39
40
41
# File 'lib/citrus/common/service/handler_service.rb', line 32

def handle route_record, msg, session, &block
  handler = get_handler route_record
  unless handler
    block_given? and yield Exception.new 'failed to find the handler'
    return
  end
  handler.send(route_record['method'], msg, session) { |err, resp, args|
    block_given? and yield err, resp, args
  }
end