Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send RAW method params to handler #25

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
require 'rjr/nodes/web'

server = RJR::Nodes::Web.new :host => 'localhost', :port => 9789, :node_id => "server"

server.dispatcher.handle('method') { |i|
puts "server: #{i}"
"#{i}".upcase
}

server.listen

client = RJR::Nodes::Web.new :node_id => "client", :host => 'localhost', :port => 9666
Expand All @@ -19,4 +21,5 @@

client.invoke "http://localhost:9789", "method", "Hello World"
# => HELLO WORLD

#client.join
12 changes: 8 additions & 4 deletions lib/rjr/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,17 @@ def set_env(env)
# method parameters in the local scope
def handle
node_sig = "#{@rjr_node_id}(#{@rjr_node_type})"
method_sig = "#{@rjr_method}(#{@rjr_method_args.join(',')})"
method_sig = "#{@rjr_method}(#{@rjr_method_args})"

RJR::Logger.info "#{node_sig}->#{method_sig}"

# TODO option to compare arity of handler to number
# of method_args passed in ?
retval = instance_exec(*@rjr_method_args, &@rjr_handler)
if @rjr_method_args.is_a? Hash
# Translate Hash<String, dynamic> to Hash<Symbol, dynamic>
s_params = Hash[@rjr_method_args.map { |k, v| [k.to_sym, v] }]
instance_exec(**s_params, &rjr_handler)
else
instance_exec(*rjr_method_args, &rjr_handler)
end

RJR::Logger.info \
"#{node_sig}<-#{method_sig}<-#{retval.nil? ? "nil" : retval}"
Expand Down