Module: EM::RemoteCall
- Defined in:
- lib/em_remote_call/server.rb,
lib/em_remote_call/client.rb,
lib/em_remote_call/utils.rb
Instance Method Summary collapse
-
#remote_class_method(method_name, opts = {}) ⇒ Object
a convinience wrapper for class methods:.
- #remote_method(method_name, opts = {}) ⇒ Object
Instance Method Details
#remote_class_method(method_name, opts = {}) ⇒ Object
a convinience wrapper for class methods:
42 43 44 |
# File 'lib/em_remote_call/client.rb', line 42 def remote_class_method(method_name, opts={}) (class << self; self; end).remote_method method_name, opts.merge({:server_class_method => true}) end |
#remote_method(method_name, opts = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/em_remote_call/client.rb', line 16 def remote_method(method_name, opts={}) define_method method_name do |*method_args, &callb| return unless remote_connection = (self.class.respond_to?(:remote_connection) && self.class.remote_connection) || (self.respond_to?(:remote_connection) && self.remote_connection) callback = EM::RemoteCall::Deferrable.new callback.callback(&callb) if callb call = { :deferrable_id => callback.object_id, # store the callbacks object_id to retrieve it later :debug => opts[:debug], # debugging on client and server :method => opts[:calls] || method_name, # same method name by default :arguments => [*method_args], # all the args :instance => { :class => remote_connection.remote_class_name || self.class.to_s, # own class name by default :id => !opts[:server_class_method] && send(remote_connection.instance_finder) # when it's nil, it's considered a class method. }} puts "On Client: #{call}" if opts[:debug] remote_connection.call call return callback end end |