Class: RedPack::SimpleHashDispatcher
- Inherits:
-
Object
- Object
- RedPack::SimpleHashDispatcher
- Includes:
- MethodDispatcher
- Defined in:
- lib/redpack-ruby/method-dispatchers/simple.rb
Instance Method Summary collapse
- #dispatch(ctx, method, params) ⇒ Object
-
#initialize(dispatch_table, responder) ⇒ SimpleHashDispatcher
constructor
A new instance of SimpleHashDispatcher.
Constructor Details
#initialize(dispatch_table, responder) ⇒ SimpleHashDispatcher
Returns a new instance of SimpleHashDispatcher.
7 8 9 10 |
# File 'lib/redpack-ruby/method-dispatchers/simple.rb', line 7 def initialize(dispatch_table, responder) @dispatch_table = dispatch_table @responder = responder end |
Instance Method Details
#dispatch(ctx, method, params) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/redpack-ruby/method-dispatchers/simple.rb', line 12 def dispatch(ctx, method, params) if @dispatch_table.key? method then begin result = @dispatch_table[method].call(*params) @responder.ok(ctx, result) rescue @responder.fail(ctx, $!) end else @responder.fail(ctx, "no-such-dispatchable-key: #{method}") end end |