Class: GetStaticFieldHandler
- Inherits:
-
AbstractCommandHandler
show all
- Defined in:
- lib/javonet-ruby-sdk/core/handler/get_static_field_handler.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/core/handler/get_static_field_handler.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/core/handler/get_static_field_handler.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/get_static_field_handler.rb
Instance Method Summary
collapse
#handle_command, #iterate
Constructor Details
Returns a new instance of GetStaticFieldHandler.
4
5
6
|
# File 'lib/javonet-ruby-sdk/core/handler/get_static_field_handler.rb', line 4
def initialize
@required_parameters_count = 2
end
|
Instance Method Details
#get_static_field(command) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/javonet-ruby-sdk/core/handler/get_static_field_handler.rb', line 12
def get_static_field(command)
begin
if command.payload.length != @required_parameters_count
raise ArgumentError.new "Static field parameters mismatch"
end
merged_value = '@@' + command.payload[1]
if command.payload[0].class_variable_defined?(merged_value)
response = command.payload[0].class_variable_get(merged_value)
else
response = command.payload[0].const_get(command.payload[1])
end
return response
rescue NameError
fields = command.payload[0].class_variables
message = "Field #{command.payload[1]} not found in class #{command.payload[0].name}. Available fields:\n"
fields.each { |field_iter| message += "#{field_iter}\n" }
raise Exception, message
rescue Exception => e
return e
end
end
|
#process(command) ⇒ Object
8
9
10
|
# File 'lib/javonet-ruby-sdk/core/handler/get_static_field_handler.rb', line 8
def process(command)
get_static_field(command)
end
|