Sha256: 6082f09046cfa2a5720fbf4ba85f9029dea3639b8c6ebece9c4ac903e6d71854

Contents?: true

Size: 1.05 KB

Versions: 28

Compression:

Stored size: 1.05 KB

Contents

require_relative 'abstract_command_handler'

class GetInstanceFieldHandler < AbstractCommandHandler
  def initialize
    @required_parameters_count = 2
  end

  def process(command)
    get_instance_field(command)
  end

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

      merged_value = '@' + command.payload[1]
      if command.payload[0].instance_variable_defined?(merged_value)
        response = command.payload[0].instance_variable_get(merged_value)
      else
        raise "Instance field not defined"
      end
      return response
    rescue NameError
      fields = command.payload[0].instance_variables
      message = "Field #{command.payload[1]} not found in object of class #{command.payload[0].class.name}. Available fields:\n"
      fields.each { |field_iter| message += "#{field_iter}\n" }
      raise Exception, message
    rescue Exception => e
      return e
    end
  end
end

Version data entries

28 entries across 14 versions & 1 rubygems

Version Path
javonet-ruby-sdk-2.5.7 lib/javonet-ruby-sdk/core/handler/get_instance_field_handler.rb
javonet-ruby-sdk-2.5.7 lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/get_instance_field_handler.rb
javonet-ruby-sdk-2.5.6 lib/javonet-ruby-sdk/core/handler/get_instance_field_handler.rb
javonet-ruby-sdk-2.5.6 lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/get_instance_field_handler.rb
javonet-ruby-sdk-2.5.5 lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/get_instance_field_handler.rb
javonet-ruby-sdk-2.5.5 lib/javonet-ruby-sdk/core/handler/get_instance_field_handler.rb
javonet-ruby-sdk-2.5.4 lib/javonet-ruby-sdk/core/handler/get_instance_field_handler.rb
javonet-ruby-sdk-2.5.4 lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/get_instance_field_handler.rb
javonet-ruby-sdk-2.5.3 lib/javonet-ruby-sdk/core/handler/get_instance_field_handler.rb
javonet-ruby-sdk-2.5.3 lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/get_instance_field_handler.rb
javonet-ruby-sdk-2.5.2 lib/javonet-ruby-sdk/core/handler/get_instance_field_handler.rb
javonet-ruby-sdk-2.5.2 lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/get_instance_field_handler.rb
javonet-ruby-sdk-2.5.1 lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/get_instance_field_handler.rb
javonet-ruby-sdk-2.5.1 lib/javonet-ruby-sdk/core/handler/get_instance_field_handler.rb
javonet-ruby-sdk-2.5.0 lib/javonet-ruby-sdk/core/handler/get_instance_field_handler.rb
javonet-ruby-sdk-2.5.0 lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/get_instance_field_handler.rb
javonet-ruby-sdk-2.4.11 lib/javonet-ruby-sdk/core/handler/get_instance_field_handler.rb
javonet-ruby-sdk-2.4.11 lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/get_instance_field_handler.rb
javonet-ruby-sdk-2.4.10 lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/get_instance_field_handler.rb
javonet-ruby-sdk-2.4.10 lib/javonet-ruby-sdk/core/handler/get_instance_field_handler.rb