Class: Bigcommerce::Lightstep::Interceptors::Registry
- Inherits:
-
Object
- Object
- Bigcommerce::Lightstep::Interceptors::Registry
- Defined in:
- lib/bigcommerce/lightstep/interceptors/registry.rb
Overview
Thread-safe registry for interceptors
Instance Method Summary collapse
-
#all ⇒ Array<Object>
Load and return all items.
-
#clear ⇒ Object
Clear the registry.
-
#count ⇒ Integer
The number of items currently loaded.
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
-
#list ⇒ Array<Class>
Return a list of the classes in the registry in their execution order.
-
#use(klass, options = {}) ⇒ Object
Add to the thread-safe registry.
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
25 26 27 |
# File 'lib/bigcommerce/lightstep/interceptors/registry.rb', line 25 def initialize @registry = [] end |
Instance Method Details
#all ⇒ Array<Object>
Load and return all items
81 82 83 84 85 86 87 |
# File 'lib/bigcommerce/lightstep/interceptors/registry.rb', line 81 def all registry_mutex do @registry.map do |o| o[:klass].is_a?(Class) ? o[:klass].new(o[:options]) : o[:klass] end end end |
#clear ⇒ Object
Clear the registry
47 48 49 50 51 |
# File 'lib/bigcommerce/lightstep/interceptors/registry.rb', line 47 def clear registry_mutex do @registry = [] end end |
#count ⇒ Integer
Returns The number of items currently loaded.
56 57 58 59 60 61 |
# File 'lib/bigcommerce/lightstep/interceptors/registry.rb', line 56 def count registry_mutex do @registry ||= [] @registry.count end end |
#list ⇒ Array<Class>
Return a list of the classes in the registry in their execution order
68 69 70 71 72 73 74 |
# File 'lib/bigcommerce/lightstep/interceptors/registry.rb', line 68 def list registry_mutex do @registry.map do |h| h[:klass].instance_of?(Class) ? h[:klass] : h[:klass].class end end end |
#use(klass, options = {}) ⇒ Object
Add to the thread-safe registry
35 36 37 38 39 40 41 42 |
# File 'lib/bigcommerce/lightstep/interceptors/registry.rb', line 35 def use(klass, = {}) registry_mutex do @registry << { klass: klass, options: } end end |