Class: RegisterForUpdateHandler

Inherits:
AbstractCommandHandler show all
Defined in:
lib/javonet-ruby-sdk/core/handler/register_for_update_handler.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractCommandHandler

#handle_command, #iterate

Constructor Details

#initializeRegisterForUpdateHandler

Returns a new instance of RegisterForUpdateHandler.



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

def initialize
  @required_parameters_count = 2
end

Class Method Details

.get_or_create_context_dictObject



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

def self.get_or_create_context_dict
  Thread.current[:register_for_update_handler_context] ||= {}
end

Instance Method Details

#process(command) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/javonet-ruby-sdk/core/handler/register_for_update_handler.rb', line 12

def process(command)
  if command.payload.length < @required_parameters_count
    raise ArgumentError.new "Register for update parameters mismatch"
  end

  obj_to_register = command.payload[0]

  guid_to_register = nil
  if command.payload.length > 1 && command.payload[1]
    guid_to_register = command.payload[1].to_s.strip.downcase
  end

  ctx = self.class.get_or_create_context_dict
  ctx[guid_to_register] = obj_to_register
  obj_to_register
end