class Inspec::Plugin::V2::PluginBase

Base class for all plugins. Specific plugin types may inherit from this; but they must register with it.

def self.base_class_for_type(plugin_type_name)

Parameters:
  • plugin_type_name (Symbol) --
def self.base_class_for_type(plugin_type_name)
  @@plugin_type_classes[plugin_type_name]
end

def self.plugin_name(name = nil)

Parameters:
  • Name (Symbol) -- of the plugin. If a string is provided, it is converted to a Symbol.
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

def self.register_plugin_type(plugin_type_name, new_plugin_type_base_class = self)

Parameters:
  • the (Class) -- plugin type class, defaults to assuming inheritance
  • plugin_type_name (Symbol) --
def self.register_plugin_type(plugin_type_name, new_plugin_type_base_class = self)
  new_dsl_method_name = plugin_type_name
  # This lets the Inspec.plugin(2,:your_plugin_type) work
  @@plugin_type_classes[plugin_type_name] = new_plugin_type_base_class
  # This part defines the DSL command to register a concrete plugin's implementation of a plugin type
  Inspec::Plugin::V2::PluginBase.define_singleton_method(new_dsl_method_name) do |hook_name, &hook_body|
    plugin_concrete_class = self
    # Verify class is registered (i.e. plugin_name has been called)
    status = registry.find_status_by_class(plugin_concrete_class)
    if status.nil?
      raise Inspec::Plugin::V2::LoadError, "You must call 'plugin_name' prior to calling #{plugin_type_name} for plugin class #{plugin_concrete_class}"
    end
    # Construct the Activator record
    activator = Inspec::Plugin::V2::Activator.new
    activator.plugin_name = plugin_concrete_class.plugin_name
    activator.plugin_type = plugin_type_name
    activator.activator_name = hook_name.to_sym
    activator.activation_proc = hook_body
    status.activators << activator
  end
end

def self.registry

@returns [Inspec::Plugin::V2::Registry] the singleton Plugin Registry object.
The global registry.
def self.registry
  Inspec::Plugin::V2::Registry.instance
end