Class: EM::RemoteCall::Call

Inherits:
Object
  • Object
show all
Defined in:
lib/em_remote_call/server.rb

Defined Under Namespace

Classes: Error, NoInstanceError, NoMethodGivenError, NoMethodOfInstanceError

Instance Method Summary collapse

Constructor Details

#initialize(instance_opts, method, arguments) ⇒ Call

Returns a new instance of Call.



9
10
11
12
13
14
# File 'lib/em_remote_call/server.rb', line 9

def initialize(instance_opts, method, arguments)
  @arguments = arguments
  @method    = method                       or raise NoMethodError.new method
  @instance  = find_instance(instance_opts) or raise NoInstanceError.new instance_opts
  @instance.respond_to?(@method)            or raise NoMethodOfInstanceError.new "#{@instance}##{method}"
end

Instance Method Details

#call(&callb) ⇒ Object



32
33
34
# File 'lib/em_remote_call/server.rb', line 32

def call(&callb)
  @arguments.empty? ? @instance.__send__(@method, &callb) : @instance.__send__(@method, *@arguments, &callb)
end

#find_instance(args) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/em_remote_call/server.rb', line 16

def find_instance(args)
  if args[:id]
    klass = EM::RemoteCall::Utils.constantize(args[:class])      or return false
    @instance = klass.find(args[:id])                            or return false
  else
    @instance = EM::RemoteCall::Utils.constantize(args[:class])  or return false
  end
end

#takes_block?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
# File 'lib/em_remote_call/server.rb', line 25

def takes_block?
  method = @instance.method(@method)
  return unless method.respond_to?(:parameters)
  params = method.parameters
  params.last && params.last.first == :block
end