Class: RubyHandler

Inherits:
AbstractHandler show all
Defined in:
lib/javonet-ruby-sdk/core/handler/ruby_handler.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/core/handler/ruby_handler.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/core/handler/ruby_handler.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/core/handler/ruby_handler.rb

Instance Method Summary collapse

Constructor Details

#initializeRubyHandler

Returns a new instance of RubyHandler.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/javonet-ruby-sdk/core/handler/ruby_handler.rb', line 21

def initialize
  super
  load_library_handler = LoadLibraryHandler.new
  invoke_static_method_handler = InvokeStaticMethodHandler.new
  get_static_field_handler = GetStaticFieldHandler.new
  get_class_instance_handler = CreateClassInstanceHandler.new
  set_static_field_handler = SetStaticFieldHandler.new
  get_type_handler = GetTypeHandler.new
  invoke_instance_method_handler = InvokeInstanceMethodHandler.new
  resolve_instance_handler = ResolveInstanceHandler.new
  casting_handler = CastingHandler.new
  get_instance_field_handler = GetInstanceFieldHandler.new
  destruct_reference_handler = DestructReferenceHandler.new

  $handler_dict[RubyCommandType::LOAD_LIBRARY] = load_library_handler
  $handler_dict[RubyCommandType::INVOKE_STATIC_METHOD] = invoke_static_method_handler
  $handler_dict[RubyCommandType::GET_STATIC_FIELD] = get_static_field_handler
  $handler_dict[RubyCommandType::CREATE_CLASS_INSTANCE] = get_class_instance_handler
  $handler_dict[RubyCommandType::SET_STATIC_FIELD] = set_static_field_handler
  $handler_dict[RubyCommandType::GET_TYPE] = get_type_handler
  $handler_dict[RubyCommandType::INVOKE_INSTANCE_METHOD] = invoke_instance_method_handler
  $handler_dict[RubyCommandType::REFERENCE] = resolve_instance_handler
  $handler_dict[RubyCommandType::CAST] = casting_handler
  $handler_dict[RubyCommandType::GET_INSTANCE_FIELD] = get_instance_field_handler
  $handler_dict[RubyCommandType::DESTRUCT_REFERENCE] = destruct_reference_handler
end

Instance Method Details

#handle_command(ruby_command) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/javonet-ruby-sdk/core/handler/ruby_handler.rb', line 49

def handle_command(ruby_command)
  response = $handler_dict[ruby_command.command_type].handle_command(ruby_command)
  reference_cache = ReferencesCache.instance
    if response.is_a? String or response.is_a? Float or response.is_a? Integer or response.is_a? TrueClass or response.is_a? FalseClass
      return RubyCommand.new(RuntimeLib::RUBY, RubyCommandType::RESPONSE, [response])
    elsif response.is_a? Exception
      return RubyCommand.new(RuntimeLib::RUBY, RubyCommandType::EXCEPTION, ["RubyException: " + response.to_s])
    else
      guid = reference_cache.cache_reference(response)
      return RubyCommand.new(RuntimeLib::RUBY, RubyCommandType::REFERENCE, [guid])
    end
end