Sha256: c03e2c81ef9e7358eb61c40c4df89f0a42ad4c09743c8736e071604dae2bc7cb

Contents?: true

Size: 1.3 KB

Versions: 37

Compression:

Stored size: 1.3 KB

Contents

require 'yaml'

module RailsAudit
  class Runner
    def initialize
      @config = { 'Concurrency' => true, 'Rails' => true }
      if File.exist? 'config/audit.yml'
        @config = @config.merge YAML.load_file('config/audit.yml')
      end
    end

    def get_config(name)
      defaults = { 'Parameters' => '', 'Enabled' => true }
      config = defaults.merge(@config[name] || {})
      {
        rails: @config['Rails'],
        params: config['Parameters'],
        enabled: config['Enabled']
      }
    end

    def run
      concurrency = @config['Concurrency']

      failures = concurrency && run_threads || run_sequence

      if failures.any?
        puts 'Failed tests:'
        failures.each { |f| puts f }
      end

      failures.none?
    end

    def run_sequence
      failures = []

      Audits::ALL.each do |audit|
        success = audit.run get_config(audit.get_name)
        failures << audit.get_name unless success
      end

      failures
    end

    def run_threads
      failures = []
      mutex = Mutex.new

      threads = Audits::ALL.map do |audit|
        Thread.new do
          success = audit.run get_config(audit.get_name)
          mutex.synchronize { failures << audit.get_name unless success }
        end
      end

      threads.each { |t| t.join }

      failures
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
rails-audit-0.30.0 lib/rails-audit/runner.rb
rails-audit-0.29.0 lib/rails-audit/runner.rb
rails-audit-0.28.0 lib/rails-audit/runner.rb
rails-audit-0.27.0 lib/rails-audit/runner.rb
rails-audit-0.26.0 lib/rails-audit/runner.rb
rails-audit-0.25.0 lib/rails-audit/runner.rb
rails-audit-0.24.0 lib/rails-audit/runner.rb
rails-audit-0.23.0 lib/rails-audit/runner.rb
rails-audit-0.22.0 lib/rails-audit/runner.rb
rails-audit-0.21.0 lib/rails-audit/runner.rb
rails-audit-0.20.0 lib/rails-audit/runner.rb
rails-audit-0.19.1 lib/rails-audit/runner.rb
rails-audit-0.19.0 lib/rails-audit/runner.rb
rails-audit-0.18.0 lib/rails-audit/runner.rb
rails-audit-0.17.0 lib/rails-audit/runner.rb
rails-audit-0.16.0 lib/rails-audit/runner.rb
rails-audit-0.15.0 lib/rails-audit/runner.rb