Class: Inspec::Plugin::V2::Registry

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Singleton
Defined in:
lib/inspec/plugin/v2/registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

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

#registryObject (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

#__resetObject

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

Returns:

  • (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.

Parameters:

  • plugin_name (Symbol)

    Restricts the search to the given plugin

  • plugin_type (Symbol)

    Restricts the search to the given plugin type

  • activator_name (Symbol)

    Name of the activator

  • implementation_class (Class)

    Implementation class returned by an already-actived plugin type



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_countObject



35
36
37
# File 'lib/inspec/plugin/v2/registry.rb', line 35

def known_count
  registry.values.count
end

#loaded_countObject



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

Returns:

  • (Boolean)


27
28
29
# File 'lib/inspec/plugin/v2/registry.rb', line 27

def loaded_plugin?(name)
  registry.dig(name, :loaded)
end

#loaded_plugin_namesObject



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