Class: RedPack::SimpleInstanceDispatcher

Inherits:
Object
  • Object
show all
Includes:
MethodDispatcher
Defined in:
lib/redpack-ruby/method-dispatchers/simple.rb

Instance Method Summary collapse

Constructor Details

#initialize(target, responder) ⇒ SimpleInstanceDispatcher

Returns a new instance of SimpleInstanceDispatcher.



32
33
34
35
# File 'lib/redpack-ruby/method-dispatchers/simple.rb', line 32

def initialize(target, responder)
  @target = target
  @responder = responder
end

Instance Method Details

#dispatch(ctx, method, params) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/redpack-ruby/method-dispatchers/simple.rb', line 37

def dispatch(ctx, method, params)
  if @target.respond_to? method then
    begin
      result = @target.send(method, *params)
      @responder.ok(ctx, result)
    rescue
      @responder.fail(ctx, $!)
    end
  else
    @responder.fail(ctx, "no-such-method: #{method} on: #{target}")
  end
end