Class: InvokeInstanceMethodHandler
- Inherits:
-
AbstractHandler
show all
- Defined in:
- lib/hypertube-ruby-sdk/core/handler/invoke_instance_method_handler.rb
Instance Method Summary
collapse
#handle_command, #validate
Constructor Details
Returns a new instance of InvokeInstanceMethodHandler.
6
7
8
|
# File 'lib/hypertube-ruby-sdk/core/handler/invoke_instance_method_handler.rb', line 6
def initialize
@required_parameters_count = 2
end
|
Instance Method Details
#invoke_instance_method(command) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/hypertube-ruby-sdk/core/handler/invoke_instance_method_handler.rb', line 14
def invoke_instance_method(command)
validate(command, @required_parameters_count, self.class.name)
instance = command.payload[0]
method_name = command.payload[1]
return instance.send(method_name) unless command.payload.length > 2
arguments = command.payload[2..]
instance.send(method_name, *arguments)
rescue NoMethodError => e
puts e.message
methods = instance.methods
message = "Method #{method_name} not found in object of class #{instance.class.name}. Available methods:\n"
methods.each { |method_iter| message += "#{method_iter}\n" }
raise Exception, message
end
|
#process(command) ⇒ Object
10
11
12
|
# File 'lib/hypertube-ruby-sdk/core/handler/invoke_instance_method_handler.rb', line 10
def process(command)
invoke_instance_method(command)
end
|