Method: Inspec::PluginCtl#initialize

Defined in:
lib/inspec/plugins.rb

#initialize(home = nil) ⇒ PluginCtl

Returns a new instance of PluginCtl.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/inspec/plugins.rb', line 26

def initialize(home = nil)
  @paths = []

  # load plugins in the same gem installation
  lib_home = File.expand_path(File.join(__FILE__, '..', '..', '..', '..'))
  @paths += Dir[lib_home+'/inspec-*-*/lib/inspec-*rb']

  # traverse out of inspec-vX.Y.Z/lib/inspec/plugins.rb
  @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