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
- #path_based_plugin?(name) ⇒ Boolean
- #register(name, status) ⇒ Object (also: #[]=)
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
21 22 23 |
# File 'lib/inspec/plugin/v2/registry.rb', line 21 def initialize @registry = {} end |
Instance Attribute Details
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
13 14 15 |
# File 'lib/inspec/plugin/v2/registry.rb', line 13 def registry @registry end |
Instance Method Details
#__reset ⇒ Object
Provided for test support. Purges the registry.
81 82 83 |
# File 'lib/inspec/plugin/v2/registry.rb', line 81 def __reset @registry.clear end |
#any_load_failures? ⇒ Boolean
25 26 27 |
# File 'lib/inspec/plugin/v2/registry.rb', line 25 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.
62 63 64 65 66 67 68 |
# File 'lib/inspec/plugin/v2/registry.rb', line 62 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
52 53 54 |
# File 'lib/inspec/plugin/v2/registry.rb', line 52 def find_status_by_class(klass) registry.values.detect { |status| status.plugin_class == klass } end |
#known_count ⇒ Object
40 41 42 |
# File 'lib/inspec/plugin/v2/registry.rb', line 40 def known_count registry.values.count end |
#loaded_count ⇒ Object
36 37 38 |
# File 'lib/inspec/plugin/v2/registry.rb', line 36 def loaded_count loaded_plugin_names.count end |
#loaded_plugin?(name) ⇒ Boolean
29 30 31 32 33 34 |
# File 'lib/inspec/plugin/v2/registry.rb', line 29 def loaded_plugin?(name) # HACK: Status is normally the source of truth for loadedness, unless it is a train plugin; then the Train::Registry is the source of truth. # Also, InSpec registry is keyed on Symbols; Train is keyed on Strings. return registry.dig(name.to_sym, :loaded) unless name.to_s.start_with?('train-') Train::Plugins.registry.key?(name.to_s.sub(/^train-/, '')) end |
#loaded_plugin_names ⇒ Object
44 45 46 |
# File 'lib/inspec/plugin/v2/registry.rb', line 44 def loaded_plugin_names registry.keys.select { |name| loaded_plugin?(name) } end |
#path_based_plugin?(name) ⇒ Boolean
48 49 50 |
# File 'lib/inspec/plugin/v2/registry.rb', line 48 def path_based_plugin?(name) known_plugin?(name.to_sym) && registry[name.to_sym].installation_type == :path end |
#register(name, status) ⇒ Object Also known as: []=
70 71 72 73 74 75 76 |
# File 'lib/inspec/plugin/v2/registry.rb', line 70 def register(name, status) if known_plugin? name Inspec::Log.debug "PluginLoader: refusing to re-register plugin '#{name}': an existing plugin with that name was loaded via #{registry[name].installation_type}-loading from #{registry[name].entry_point}" else registry[name.to_sym] = status end end |