Class: ProjectResultAsDtoHandler

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

Instance Method Summary collapse

Methods inherited from AbstractCommandHandler

#handle_command, #iterate

Constructor Details

#initializeProjectResultAsDtoHandler

Returns a new instance of ProjectResultAsDtoHandler.



9
10
11
# File 'lib/hypertube-ruby-sdk/core/handler/project_result_as_dto_handler.rb', line 9

def initialize
  @required_parameters_count = 1
end

Instance Method Details

#process(command) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/hypertube-ruby-sdk/core/handler/project_result_as_dto_handler.rb', line 13

def process(command)
  instance = command.payload[0]
  response_array = []
  response_array[0] = instance

  type_name = instance.nil? ? '' : instance.class.name
  response_array[1] = Command.new(command.runtime_name, CommandType::GET_TYPE, type_name)

  get_instance_field_handler = GetInstanceFieldHandler.new
  (1...command.payload.length).each do |i|
    property_name = command.payload[i]
    property_value = get_instance_field_handler.process(
      Command.new(command.runtime_name, CommandType::GET_INSTANCE_FIELD, instance, property_name)
    )
    response_array[i + 1] = Command.new(
      command.runtime_name,
      CommandType::DTO_PROPERTY,
      property_name,
      property_value
    )
  end

  response_array
end