Class: Inspec::Plugin::V2::Registry
- Inherits:
-
Object
- Object
- Inspec::Plugin::V2::Registry
- Extended by:
- Forwardable
- Includes:
- Singleton
- Defined in:
- lib/inspec/plugin/v2/registry.rb
Instance Attribute Summary collapse
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
Instance Method Summary collapse
-
#__reset ⇒ Object
Provided for test support.
- #any_load_failures? ⇒ Boolean
-
#find_activators(filters = {}) ⇒ Object
Finds Activators matching criteria (all optional) you specify as a Hash.
- #find_status_by_class(klass) ⇒ Object
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #known_count ⇒ Object
- #loaded_count ⇒ Object
- #loaded_plugin?(name) ⇒ Boolean
- #loaded_plugin_names ⇒ Object
- #register(name, status) ⇒ Object (also: #[]=)
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
19 20 21 |
# File 'lib/inspec/plugin/v2/registry.rb', line 19 def initialize @registry = {} end |
Instance Attribute Details
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
11 12 13 |
# File 'lib/inspec/plugin/v2/registry.rb', line 11 def registry @registry end |
Instance Method Details
#__reset ⇒ Object
Provided for test support. Purges the registry.
72 73 74 |
# File 'lib/inspec/plugin/v2/registry.rb', line 72 def __reset @registry.clear end |
#any_load_failures? ⇒ Boolean
23 24 25 |
# File 'lib/inspec/plugin/v2/registry.rb', line 23 def any_load_failures? !plugin_statuses.select(&:load_exception).empty? end |
#find_activators(filters = {}) ⇒ Object
Finds Activators matching criteria (all optional) you specify as a Hash.
53 54 55 56 57 58 59 |
# File 'lib/inspec/plugin/v2/registry.rb', line 53 def find_activators(filters = {}) plugin_statuses.map(&:activators).flatten.select do |act| [:plugin_name, :plugin_type, :activator_name, :implementation_class].all? do |criteria| !filters.key?(criteria) || act[criteria] == filters[criteria] end end end |
#find_status_by_class(klass) ⇒ Object
43 44 45 |
# File 'lib/inspec/plugin/v2/registry.rb', line 43 def find_status_by_class(klass) registry.values.detect { |status| status.plugin_class == klass } end |
#known_count ⇒ Object
35 36 37 |
# File 'lib/inspec/plugin/v2/registry.rb', line 35 def known_count registry.values.count end |
#loaded_count ⇒ Object
31 32 33 |
# File 'lib/inspec/plugin/v2/registry.rb', line 31 def loaded_count registry.values.select(&:loaded).count end |
#loaded_plugin?(name) ⇒ Boolean
27 28 29 |
# File 'lib/inspec/plugin/v2/registry.rb', line 27 def loaded_plugin?(name) registry.dig(name, :loaded) end |
#loaded_plugin_names ⇒ Object
39 40 41 |
# File 'lib/inspec/plugin/v2/registry.rb', line 39 def loaded_plugin_names registry.values.select(&:loaded).map(&:name) end |
#register(name, status) ⇒ Object Also known as: []=
61 62 63 64 65 66 67 |
# File 'lib/inspec/plugin/v2/registry.rb', line 61 def register(name, status) if known_plugin? name Inspec::Log.warn "PluginLoader: refusing to re-register plugin '#{name}': an existing plugin with that name was loaded via #{existing.installation_type}-loading from #{existing.entry_point}" else registry[name.to_sym] = status end end |