Method: Inspec::Plugin::V2::PluginBase.register_plugin_type
- Defined in:
- lib/inspec/plugin/v2/plugin_base.rb
.register_plugin_type(plugin_type_name, new_plugin_type_base_class = self) ⇒ Object
Inform the plugin system of a new plgin type. This has the following effects:
* enables Inspec.plugin(2, :your_type_here) to return the plugin
type base class
* defines the DSL method with the same name as the plugin type.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/inspec/plugin/v2/plugin_base.rb', line 26 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 |