Class: Hypertube::Core::NamespaceCache::NamespaceCache
- Inherits:
-
Object
- Object
- Hypertube::Core::NamespaceCache::NamespaceCache
- Defined in:
- lib/hypertube-ruby-sdk/core/namespace_cache/namespace_cache.rb
Instance Attribute Summary collapse
-
#namespace_cache ⇒ Object
Returns the value of attribute namespace_cache.
Class Method Summary collapse
Instance Method Summary collapse
- #cache_namespace(namespace_regex) ⇒ Object
- #clear_cache ⇒ Object
- #get_cached_namespaces ⇒ Object
-
#initialize ⇒ NamespaceCache
constructor
A new instance of NamespaceCache.
- #is_namespace_cache_empty? ⇒ Boolean
- #is_type_allowed(type_to_check) ⇒ Object
Constructor Details
#initialize ⇒ NamespaceCache
Returns a new instance of NamespaceCache.
16 17 18 19 |
# File 'lib/hypertube-ruby-sdk/core/namespace_cache/namespace_cache.rb', line 16 def initialize @namespace_cache = [] @mutex = Mutex.new end |
Instance Attribute Details
#namespace_cache ⇒ Object
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
.instance ⇒ Object
7 8 9 10 11 12 |
# File 'lib/hypertube-ruby-sdk/core/namespace_cache/namespace_cache.rb', line 7 def self.instance @mutex ||= Mutex.new @mutex.synchronize do @instance ||= new end end |
Instance Method Details
#cache_namespace(namespace_regex) ⇒ Object
21 22 23 24 25 |
# File 'lib/hypertube-ruby-sdk/core/namespace_cache/namespace_cache.rb', line 21 def cache_namespace(namespace_regex) @mutex.synchronize do @namespace_cache << namespace_regex end end |
#clear_cache ⇒ Object
53 54 55 56 57 58 |
# File 'lib/hypertube-ruby-sdk/core/namespace_cache/namespace_cache.rb', line 53 def clear_cache @mutex.synchronize do @namespace_cache.clear end 0 end |
#get_cached_namespaces ⇒ Object
47 48 49 50 51 |
# File 'lib/hypertube-ruby-sdk/core/namespace_cache/namespace_cache.rb', line 47 def get_cached_namespaces @mutex.synchronize do @namespace_cache.dup end end |
#is_namespace_cache_empty? ⇒ Boolean
27 28 29 30 31 |
# File 'lib/hypertube-ruby-sdk/core/namespace_cache/namespace_cache.rb', line 27 def is_namespace_cache_empty? @mutex.synchronize do @namespace_cache.empty? end end |
#is_type_allowed(type_to_check) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/hypertube-ruby-sdk/core/namespace_cache/namespace_cache.rb', line 33 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 @mutex.synchronize do @namespace_cache.any? do |pattern| /#{pattern}/.match?(name_to_check) end end end |