Class: Inspec::PluginCtl

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/inspec/plugins.rb

Overview

PLEASE NOTE: The Plugin system is an internal mechanism for connecting inspec components. Its API is currently considered in an alpha state and may change between minor version revisions. A stable plugin API will be released in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(home = nil) ⇒ PluginCtl

Returns a new instance of PluginCtl.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/inspec/plugins.rb', line 24

def initialize(home = nil)
  @home = home || File.join(Dir.home, '.inspec', 'plugins')
  @paths = Dir[File.join(@home, '**{,/*/**}', '*.gemspec')]
           .map { |x| File.dirname(x) }
           .map { |x| Dir[File.join(x, 'lib', 'inspec-*.rb')] }
           .flatten

  # load bundled plugins
  bundled_dir = File.expand_path(File.dirname(__FILE__))
  @paths += Dir[File.join(bundled_dir, '..', 'bundles', 'inspec-*.rb')].flatten

  # map paths to names
  @registry = Hash[@paths.map { |x|
    [File.basename(x, '.rb'), x]
  }]
end

Instance Attribute Details

#registryObject (readonly)

Returns the value of attribute registry.



21
22
23
# File 'lib/inspec/plugins.rb', line 21

def registry
  @registry
end

Instance Method Details

#load(name) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/inspec/plugins.rb', line 41

def load(name)
  path = @registry[name]
  if path.nil?
    fail "Couldn't find plugin #{name}. Searching in #{@home}"
  end
  # puts "Loading plugin #{name} from #{path}"
  require path
end