Class: TypeCache

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTypeCache

Returns a new instance of TypeCache.



10
11
12
# File 'lib/javonet-ruby-sdk/core/type_cache/type_cache.rb', line 10

def initialize
  @type_cache = []
end

Instance Attribute Details

#type_cacheObject

Returns the value of attribute type_cache.



2
3
4
# File 'lib/javonet-ruby-sdk/core/type_cache/type_cache.rb', line 2

def type_cache
  @type_cache
end

Class Method Details

.instanceObject



4
5
6
# File 'lib/javonet-ruby-sdk/core/type_cache/type_cache.rb', line 4

def self.instance
  @instance ||= new
end

Instance Method Details

#cache_type(type_regex) ⇒ Object



14
15
16
# File 'lib/javonet-ruby-sdk/core/type_cache/type_cache.rb', line 14

def cache_type(type_regex)
  @type_cache << type_regex
end

#clear_cacheObject



38
39
40
41
# File 'lib/javonet-ruby-sdk/core/type_cache/type_cache.rb', line 38

def clear_cache
  @type_cache.clear
  0
end

#get_cached_typesObject



34
35
36
# File 'lib/javonet-ruby-sdk/core/type_cache/type_cache.rb', line 34

def get_cached_types
  @type_cache
end

#is_type_allowed(type_to_check) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/javonet-ruby-sdk/core/type_cache/type_cache.rb', line 22

def is_type_allowed(type_to_check)
  name_to_check = if type_to_check.is_a?(Module)
                    type_to_check.name
                  else
                    "#{type_to_check.class.name}::#{type_to_check.name}"
                  end

  @type_cache.any? do |pattern|
    /#{pattern}/.match?(name_to_check)
  end
end

#is_type_cache_empty?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/javonet-ruby-sdk/core/type_cache/type_cache.rb', line 18

def is_type_cache_empty?
  @type_cache.empty?
end