class Bigcommerce::Lightstep::Interceptors::Registry
Thread-safe registry for interceptors
Public Class Methods
new()
click to toggle source
# File lib/bigcommerce/lightstep/interceptors/registry.rb, line 25 def initialize @registry = [] end
Public Instance Methods
all()
click to toggle source
Load and return all items
@return [Array<Object>]
# 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()
click to toggle source
Clear the registry
# File lib/bigcommerce/lightstep/interceptors/registry.rb, line 47 def clear registry_mutex do @registry = [] end end
count()
click to toggle source
@return [Integer] The number of items currently loaded
# File lib/bigcommerce/lightstep/interceptors/registry.rb, line 56 def count registry_mutex do @registry ||= [] @registry.count end end
list()
click to toggle source
Return a list of the classes in the registry in their execution order
@return [Array<Class>]
# 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 = {})
click to toggle source
Add to the thread-safe registry
@param [Class|Object] klass The class to add or object to register. @param [Hash] options (Optional) A hash of options to pass into the class during initialization
# File lib/bigcommerce/lightstep/interceptors/registry.rb, line 35 def use(klass, options = {}) registry_mutex do @registry << { klass: klass, options: options } end end
Private Instance Methods
registry_mutex(&block)
click to toggle source
Handle mutations to the registry in a thread-safe manner
# File lib/bigcommerce/lightstep/interceptors/registry.rb, line 94 def registry_mutex(&block) @registry_mutex ||= begin require 'monitor' Monitor.new end @registry_mutex.synchronize(&block) end