class Citrus::Common::Service::HandlerService

HandlerService

Public Class Methods

new(app, handlers={}) click to toggle source

Initialize the service

@param [Object] app @param [Hash] handlers

# File lib/citrus/common/service/handler_service.rb, line 22
def initialize app, handlers={}
  @app = app
  @handlers = handlers
end

Public Instance Methods

handle(route_record, msg, session) { |exception 'failed to find the handler'| ... } click to toggle source

Handle message from the client

@param [Hash] route_record @param [Hash] msg @param [Object] session

# 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

Private Instance Methods

get_handler(route_record) click to toggle source

Get handler by route record

@param [Hash] route_record

@private

# File lib/citrus/common/service/handler_service.rb, line 50
def get_handler route_record
  handler = @handlers[route_record['handler']]
  unless handler
    return nil
  end
  unless handler.respond_to? route_record['method']
    return nil
  end
  handler
end