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.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/inspec/plugin/v2/plugin_base.rb', line 79

def self.plugin_name(name = nil)
  reg = Inspec::Plugin::V2::Registry.instance
  if name.nil?
    # If called from a Plugin definition class...
    stat = reg.find_status_by_class(self)
    return stat.name if stat

    # Called from an implementation class
    return find_name_by_implementation_class(self)
  end

  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