Class: SetStaticFieldHandler

Inherits:
AbstractCommandHandler show all
Defined in:
lib/javonet-ruby-sdk/core/handler/command_handler/set_static_field_handler.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/core/handler/command_handler/set_static_field_handler.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/core/handler/command_handler/set_static_field_handler.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/command_handler/set_static_field_handler.rb

Instance Method Summary collapse

Methods inherited from AbstractCommandHandler

#handle_command, #iterate

Constructor Details

#initializeSetStaticFieldHandler

Returns a new instance of SetStaticFieldHandler.



4
5
6
# File 'lib/javonet-ruby-sdk/core/handler/command_handler/set_static_field_handler.rb', line 4

def initialize
  @required_parameters_count = 3
end

Instance Method Details

#process(command) ⇒ Object



8
9
10
# File 'lib/javonet-ruby-sdk/core/handler/command_handler/set_static_field_handler.rb', line 8

def process(command)
  Command.new(RuntimeName::RUBY, CommandType::VALUE, [set_static_field(command)])
end

#set_static_field(command) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/javonet-ruby-sdk/core/handler/command_handler/set_static_field_handler.rb', line 12

def set_static_field(command)
  begin
    if command.payload.length != @required_parameters_count
      raise ArgumentError.new "Set static field parameters mismatch"
    end

    merged_value = '@@' + command.payload[1]
    command.payload[0].class_variable_set(merged_value, command.payload[2])
  rescue Exception => e
    return e
  end
end