Method: Sanitize.run_plugins

Defined in:
lib/what_cd/sanitize.rb

.run_plugins(path, configured_plugins) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/what_cd/sanitize.rb', line 31

def self.run_plugins(path, configured_plugins)
  @log.info "Sanitizing release located at #{path}"
  # Get this directory
  current_dir = File.dirname(__FILE__)

  # Set the context to be passed around between plugins
  context = {}
  context[:path] = path

  # Iterate over the configured plugins and dynamically execute them
  configured_plugins.each do |configured_plugin|
    file = "#{current_dir}/sanitize_plugins/#{configured_plugin}.rb"
    require file
    file_name = File.basename(file, '.rb')
     # using ActiveSupport for camelcase and constantize
    plugin = file_name.camelcase.constantize
    # Check to ensure ruby file defines a class
    if plugin.class == Class
      @log.info "Sanitizing with plugin #{plugin}"
      context = plugin.new.sanitize(context)
      @log.debug "Context returned as #{context}"
    end
  end

  @log.info "Sanitization finished. Sanitized release located at #{context[:path]}"
end