Module: Nourl
- Defined in:
- lib/nourl/core.rb,
lib/nourl/rpcable.rb,
lib/nourl/version.rb
Defined Under Namespace
Modules: RPCable
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
- .can_call?(klass, method) ⇒ Boolean
- .exec(params) ⇒ Object
- .json_rpc_format(result, error, id) ⇒ Object
- .rpc_white_list_for(class_list) ⇒ Object
Class Method Details
.can_call?(klass, method) ⇒ Boolean
15 16 17 18 19 |
# File 'lib/nourl/core.rb', line 15 def can_call?(klass, method) return true if klass == Nourl && method == 'rpc_white_list_for' return true if klass.send(:rpc_white_list).include?(method.to_sym) false end |
.exec(params) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/nourl/core.rb', line 21 def exec(params) rpc_string = JSON.parse(params['rpc_string']) class_name, method = rpc_string['method'].split(".") klass = Object.const_get(class_name.capitalize) params = rpc_string['params'] raise "No access to call #{klass.to_s}.#{method}." unless Nourl.can_call?(klass, method) #TODO: find a sexy way to do this result = if params.is_a?(Array) klass.send(method, *params.compact) else klass.send(method, params) end json_rpc_format(result, nil, rpc_string['id']) rescue => e json_rpc_format(nil, e., rpc_string['id']) end |
.json_rpc_format(result, error, id) ⇒ Object
42 43 44 |
# File 'lib/nourl/core.rb', line 42 def json_rpc_format(result, error, id) { "result" => result, "error" => error, "id" => id } end |
.rpc_white_list_for(class_list) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/nourl/core.rb', line 4 def rpc_white_list_for(class_list) class_list = [class_list] unless class_list.is_a?(Array) class_list.inject({}) do |list, class_name| klass = Object.const_get(class_name.capitalize) list[class_name] = klass.send(:rpc_white_list) list end end |