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.50.0 lib/rails-audit/runner.rb
rails-audit-0.49.0 lib/rails-audit/runner.rb
rails-audit-0.48.0 lib/rails-audit/runner.rb
rails-audit-0.47.0 lib/rails-audit/runner.rb
rails-audit-0.46.0 lib/rails-audit/runner.rb
rails-audit-0.45.0 lib/rails-audit/runner.rb
rails-audit-0.44.0 lib/rails-audit/runner.rb
rails-audit-0.43.0 lib/rails-audit/runner.rb
rails-audit-0.42.0 lib/rails-audit/runner.rb
rails-audit-0.41.0 lib/rails-audit/runner.rb
rails-audit-0.40.0 lib/rails-audit/runner.rb
rails-audit-0.39.0 lib/rails-audit/runner.rb
rails-audit-0.38.0 lib/rails-audit/runner.rb
rails-audit-0.37.0 lib/rails-audit/runner.rb
rails-audit-0.36.0 lib/rails-audit/runner.rb
rails-audit-0.35.0 lib/rails-audit/runner.rb
rails-audit-0.34.0 lib/rails-audit/runner.rb
rails-audit-0.33.0 lib/rails-audit/runner.rb
rails-audit-0.32.0 lib/rails-audit/runner.rb
rails-audit-0.31.0 lib/rails-audit/runner.rb