Method: Inspec::Plugin::V2::PluginBase.plugin_name

Defined in:
lib/inspec/plugin/v2/plugin_base.rb

.plugin_name(name = nil) ⇒ Object

If no name provided, looks up a known plugin by class and returns the name.

DSL method to declare a plugin. Once this has been called, the plugin will certainly be registered (known) with the Registry, and is eligible to be activated. This mainly handles status annotation.

Parameters:

  • Name (Symbol)

    of the plugin. If a string is provided, it is converted to a Symbol.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/inspec/plugin/v2/plugin_base.rb', line 72

def self.plugin_name(name = nil)
  reg = Inspec::Plugin::V2::Registry.instance
  return reg.find_status_by_class(self).name if name.nil?

  name = name.to_sym

  # Typically our status will already exist in the registry, from loading the
  # plugin.json. If we're being loaded, presumably entry_point,
  # installation_type, version
  # are known.
  unless reg.known_plugin?(name)
    # Under some testing situations, we may not pre-exist.
    status = Inspec::Plugin::V2::Status.new
    reg.register(name, status)
    status.entry_point = 'inline'
    status.installation_type = :mock_inline
  end

  status = reg[name]
  status.api_generation = 2
  status.plugin_class = self
  status.name = name

  name
end