Class: GetTypeHandler

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

Instance Method Summary collapse

Methods inherited from AbstractCommandHandler

#handle_command, #iterate

Constructor Details

#initializeGetTypeHandler

Returns a new instance of GetTypeHandler.



6
7
8
9
10
# File 'lib/javonet-ruby-sdk/core/handler/get_type_handler.rb', line 6

def initialize
  @required_parameters_count = 1
  @namespace_cache = NamespaceCache.instance
  @type_cache = TypeCache.instance
end

Instance Method Details

#process(command) ⇒ Object



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

def process(command)
    begin
      if command.payload.length < @required_parameters_count
        raise "#{self.class.name} parameters mismatch!"
      end

      type_to_return = _get_type_from_payload(command)

      if type_to_return.nil?
        raise "Type #{command.payload[0]} not found"
      end

      if (@namespace_cache.is_namespace_cache_empty? && @type_cache.is_type_cache_empty?) || # both caches are empty
        @namespace_cache.is_type_allowed(type_to_return) || # namespace is allowed
        @type_cache.is_type_allowed(type_to_return)
        # continue - type is allowed
      else
        allowed_namespaces = @namespace_cache.get_cached_namespaces.join(", ")
        allowed_types = @type_cache.get_cached_types.join(", ")
        raise "Type #{type_to_return.name} not allowed. \nAllowed namespaces: #{allowed_namespaces}\nAllowed types: #{allowed_types}"
      end

      type_to_return
    rescue Exception => e
      return e
    end
end