Sha256: a24aa01fb693d2412a09dbd3ca464ed5be5a17b1396766e15a60c2443238f3d3
Contents?: true
Size: 993 Bytes
Versions: 1
Compression:
Stored size: 993 Bytes
Contents
module JPC class Invoker include JPC::Helpers def initialize(handler) @handler = handler end def invoke(json) request = Oj.load(json) execute(request) end private def execute(request) method = request['method'] raise "Method #{method} is not allowed" unless @handler.send(:allowed?, method) @handler.token = request['token'] if request['token'] result = if request['params'].is_a?(Array) @handler.public_send(method, *request['params']) elsif %w(Hash String Integer).include?(request['params'].class.name) @handler.public_send(method, request['params']) else @handler.public_send(method) end make_result(request['id'], result) rescue => e make_error( request['id'], e.class.name, "Method #{method}: [#{e.class.name}] #{e.message} @ #{e.backtrace[0]}" ) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jpc-1.3.0 | lib/jpc/invoker.rb |