Class: Bigcommerce::Lightstep::Interceptors::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/bigcommerce/lightstep/interceptors/registry.rb

Overview

Thread-safe registry for interceptors

Instance Method Summary collapse

Constructor Details

#initializeRegistry

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

#allArray<Object>

Load and return all items

Returns:

  • (Array<Object>)


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

#clearObject

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

#countInteger

Returns The number of items currently loaded.

Returns:

  • (Integer)

    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

#listArray<Class>

Return a list of the classes in the registry in their execution order

Returns:

  • (Array<Class>)


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

Parameters:

  • klass (Class|Object)

    The class to add or object to register.

  • options (Hash) (defaults to: {})

    (Optional) A hash of options to pass into the class during initialization



35
36
37
38
39
40
41
42
# File 'lib/bigcommerce/lightstep/interceptors/registry.rb', line 35

def use(klass, options = {})
  registry_mutex do
    @registry << {
      klass: klass,
      options: options
    }
  end
end