Class: DtoHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/javonet-ruby-sdk/sdk/tools/dto_helper.rb

Overview

Helper class for working with Data Transfer Objects (DTOs) in Javonet. Provides utility methods for accessing and managing DTO field values.

Class Method Summary collapse

Class Method Details

.try_get_dto_field_value(command, field_name) ⇒ Object

Attempts to retrieve a DTO field value by field name from a command chain.

Parameters:

  • The command to search through.

  • The name of the field to retrieve.

Returns:

  • value - found is true if the field was found, value is the retrieved value or nil.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/javonet-ruby-sdk/sdk/tools/dto_helper.rb', line 15

def try_get_dto_field_value(command, field_name)
  current_command = command

  while current_command
    if current_command.command_type == CommandType::SET_INSTANCE_FIELD &&
       try_get_dto_field_name?(current_command) &&
       get_dto_field_name(current_command) == field_name
      return try_get_dto_field_value_from_command(current_command)
    end

    payload = current_command.payload
    break if payload.nil? || payload.empty?

    first_payload = payload[0]
    current_command = first_payload.is_a?(Command) ? first_payload : nil
  end

  return nil
end