Sha256: 37e26f2e2a71b7106d3bdffc5d754f04820fbdf8df4cef25734fdbe8cd830561

Contents?: true

Size: 1.05 KB

Versions: 12

Compression:

Stored size: 1.05 KB

Contents

require_relative 'abstract_command_handler'

class GetStaticFieldHandler < AbstractCommandHandler
  def initialize
    @required_parameters_count = 2
  end

  def process(command)
    return get_static_field(command)
  end

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

      merged_value = '@@' + command.payload[1]
      if command.payload[0].class_variable_defined?(merged_value)
        response = command.payload[0].class_variable_get(merged_value)
      else
        response = command.payload[0].const_get(command.payload[1])
      end
      return response
    rescue NameError
      fields = command.payload[0].class_variables
      message = "Field #{command.payload[1]} not found in class #{command.payload[0].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

12 entries across 6 versions & 1 rubygems

Version Path
javonet-ruby-sdk-2.4.5 lib/javonet-ruby-sdk/core/handler/command_handler/get_static_field_handler.rb
javonet-ruby-sdk-2.4.5 lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/command_handler/get_static_field_handler.rb
javonet-ruby-sdk-2.4.4 lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/command_handler/get_static_field_handler.rb
javonet-ruby-sdk-2.4.4 lib/javonet-ruby-sdk/core/handler/command_handler/get_static_field_handler.rb
javonet-ruby-sdk-2.4.3 lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/command_handler/get_static_field_handler.rb
javonet-ruby-sdk-2.4.3 lib/javonet-ruby-sdk/core/handler/command_handler/get_static_field_handler.rb
javonet-ruby-sdk-2.4.2 lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/command_handler/get_static_field_handler.rb
javonet-ruby-sdk-2.4.2 lib/javonet-ruby-sdk/core/handler/command_handler/get_static_field_handler.rb
javonet-ruby-sdk-2.3.0 lib/javonet-ruby-sdk/core/handler/command_handler/get_static_field_handler.rb
javonet-ruby-sdk-2.3.0 lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/command_handler/get_static_field_handler.rb
javonet-ruby-sdk-2.2.0 lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/command_handler/get_static_field_handler.rb
javonet-ruby-sdk-2.2.0 lib/javonet-ruby-sdk/core/handler/command_handler/get_static_field_handler.rb