Class: Hypertube::Core::NamespaceCache::NamespaceCache

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNamespaceCache

Returns a new instance of NamespaceCache.



13
14
15
# File 'lib/hypertube-ruby-sdk/core/namespace_cache/namespace_cache.rb', line 13

def initialize
  @namespace_cache = []
end

Instance Attribute Details

#namespace_cacheObject

Returns the value of attribute namespace_cache.



5
6
7
# File 'lib/hypertube-ruby-sdk/core/namespace_cache/namespace_cache.rb', line 5

def namespace_cache
  @namespace_cache
end

Class Method Details

.instanceObject



7
8
9
# File 'lib/hypertube-ruby-sdk/core/namespace_cache/namespace_cache.rb', line 7

def self.instance
  @instance ||= new
end

Instance Method Details

#cache_namespace(namespace_regex) ⇒ Object



17
18
19
# File 'lib/hypertube-ruby-sdk/core/namespace_cache/namespace_cache.rb', line 17

def cache_namespace(namespace_regex)
  @namespace_cache << namespace_regex
end

#clear_cacheObject



41
42
43
44
# File 'lib/hypertube-ruby-sdk/core/namespace_cache/namespace_cache.rb', line 41

def clear_cache
  @namespace_cache.clear
  0
end

#get_cached_namespacesObject



37
38
39
# File 'lib/hypertube-ruby-sdk/core/namespace_cache/namespace_cache.rb', line 37

def get_cached_namespaces
  @namespace_cache
end

#is_namespace_cache_empty?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/hypertube-ruby-sdk/core/namespace_cache/namespace_cache.rb', line 21

def is_namespace_cache_empty?
  @namespace_cache.empty?
end

#is_type_allowed(type_to_check) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/hypertube-ruby-sdk/core/namespace_cache/namespace_cache.rb', line 25

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}"
                  end

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