Class: InvokeGlobalFunctionHandler
Instance Method Summary
collapse
#handle_command, #iterate
Instance Method Details
#invoke_function(command) ⇒ Object
10
11
12
13
14
15
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/javonet-ruby-sdk/core/handler/invoke_global_function_handler.rb', line 10
def invoke_function(command)
payload = command.payload
raise ArgumentError, 'InvokeGlobalFunction requires at least one parameter' if payload.empty?
full_method_string = payload[0]
unless full_method_string.is_a?(String) && full_method_string.include?('.')
raise ArgumentError, "Expected a string in the format 'ModuleName.function_name'"
end
parts = full_method_string.split('.')
raise ArgumentError, "Invalid function identifier format. Expected 'ModuleName.function_name'" if parts.size < 2
function_name = parts.pop
module_name = parts.join('::')
target = Object.const_get(module_name)
args = payload[1..-1] || []
if target.respond_to?(function_name)
target.send(function_name, *args)
else
available_methods = target.methods.join(', ')
raise NoMethodError,
"Method #{function_name} not found in module #{module_name}. Available methods: #{available_methods}"
end
rescue NameError => e
raise NameError, "Module/Class #{module_name} not found: #{e.message}"
end
|
#process(command) ⇒ Object
6
7
8
|
# File 'lib/javonet-ruby-sdk/core/handler/invoke_global_function_handler.rb', line 6
def process(command)
invoke_function(command)
end
|