Class: Hedra::PluginManager

Inherits:
Object
  • Object
show all
Defined in:
lib/hedra/plugin_manager.rb

Instance Method Summary collapse

Constructor Details

#initializePluginManager

Returns a new instance of PluginManager.



7
8
9
10
11
# File 'lib/hedra/plugin_manager.rb', line 7

def initialize
  @plugin_dir = Config.plugin_dir
  FileUtils.mkdir_p(@plugin_dir)
  load_plugins
end

Instance Method Details

#install(path) ⇒ Object

Raises:



17
18
19
20
21
22
23
24
# File 'lib/hedra/plugin_manager.rb', line 17

def install(path)
  raise Error, "Plugin file not found: #{path}" unless File.exist?(path)

  plugin_name = File.basename(path)
  dest = File.join(@plugin_dir, plugin_name)
  FileUtils.cp(path, dest)
  load_plugin(dest)
end

#list_pluginsObject



13
14
15
# File 'lib/hedra/plugin_manager.rb', line 13

def list_plugins
  Dir.glob(File.join(@plugin_dir, '*.rb')).map { |f| File.basename(f, '.rb') }
end

#remove(name) ⇒ Object

Raises:



26
27
28
29
30
31
# File 'lib/hedra/plugin_manager.rb', line 26

def remove(name)
  plugin_file = File.join(@plugin_dir, "#{name}.rb")
  raise Error, "Plugin not found: #{name}" unless File.exist?(plugin_file)

  FileUtils.rm(plugin_file)
end

#run_checks(headers) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/hedra/plugin_manager.rb', line 33

def run_checks(headers)
  findings = []

  @plugins.each do |plugin|
    result = plugin.check(headers)
    findings.concat(result) if result.is_a?(Array)
  rescue StandardError => e
    warn "Plugin #{plugin.class.name} failed: #{e.message}"
  end

  findings
end