class Inspec::Plugin::V2::Registry
Attributes
registry[R]
Public Class Methods
new()
click to toggle source
# File lib/inspec/plugin/v2/registry.rb, line 21 def initialize @registry = {} end
Public Instance Methods
__reset()
click to toggle source
Provided for test support. Purges the registry.
# File lib/inspec/plugin/v2/registry.rb, line 94 def __reset @registry.clear end
any_load_failures?()
click to toggle source
# File lib/inspec/plugin/v2/registry.rb, line 25 def any_load_failures? !plugin_statuses.select(&:load_exception).empty? end
find_activator(filters = {})
click to toggle source
Convenience method for when you expect exactly one
# File lib/inspec/plugin/v2/registry.rb, line 72 def find_activator(filters = {}) matched_plugins = find_activators(filters) if matched_plugins.count > 1 raise Inspec::Plugin::V2::LoadError, "Plugin hooks search returned multiple results for filter #{filters.inspect} - use more filters, or use find_activators (plural)" elsif matched_plugins.empty? raise Inspec::Plugin::V2::LoadError, "Plugin hooks search returned zero results for filter #{filters.inspect}" end matched_plugins.first end
find_activators(filters = {})
click to toggle source
Finds Activators matching criteria (all optional) you specify as a Hash
. @param [Symbol] plugin_name Restricts the search to the given plugin @param [Symbol] plugin_type Restricts the search to the given plugin type @param [Symbol] activator_name Name of the activator @param [Class] implementation_class Implementation class returned by an already-actived plugin type @returns [Array] Possibly empty array of Activators
# File lib/inspec/plugin/v2/registry.rb, line 63 def find_activators(filters = {}) plugin_statuses.map(&:activators).flatten.select do |act| %i{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)
click to toggle source
# File lib/inspec/plugin/v2/registry.rb, line 53 def find_status_by_class(klass) registry.values.detect { |status| status.plugin_class == klass } end
known_count()
click to toggle source
# File lib/inspec/plugin/v2/registry.rb, line 41 def known_count registry.values.count end
loaded_count()
click to toggle source
# File lib/inspec/plugin/v2/registry.rb, line 37 def loaded_count loaded_plugin_names.count end
loaded_plugin?(name)
click to toggle source
# 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()
click to toggle source
# File lib/inspec/plugin/v2/registry.rb, line 45 def loaded_plugin_names registry.keys.select { |name| loaded_plugin?(name) } end
path_based_plugin?(name)
click to toggle source
# File lib/inspec/plugin/v2/registry.rb, line 49 def path_based_plugin?(name) known_plugin?(name.to_sym) && registry[name.to_sym].installation_type == :path end
register(name, status)
click to toggle source
# File lib/inspec/plugin/v2/registry.rb, line 83 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
Also aliased as: []=