Class: Codeqa::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/codeqa/runner.rb

Constant Summary collapse

@@registered_checkers =
reset_checkers

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sourcefile) ⇒ Runner

Returns a new instance of Runner.



27
28
29
30
# File 'lib/codeqa/runner.rb', line 27

def initialize(sourcefile)
  @sourcefile = sourcefile
  @results = []
end

Instance Attribute Details

#resultsObject (readonly)

the results (checker instances of the run)



47
48
49
# File 'lib/codeqa/runner.rb', line 47

def results
  @results
end

#sourcefileObject (readonly)

Returns the value of attribute sourcefile.



31
32
33
# File 'lib/codeqa/runner.rb', line 31

def sourcefile
  @sourcefile
end

Class Method Details

.register_checker(checker_class) ⇒ Object



14
15
16
# File 'lib/codeqa/runner.rb', line 14

def register_checker(checker_class)
  @@registered_checkers << checker_class
end

.registered_checkersObject



6
7
8
# File 'lib/codeqa/runner.rb', line 6

def registered_checkers
  @@registered_checkers
end

.reset_checkersObject



10
11
12
# File 'lib/codeqa/runner.rb', line 10

def reset_checkers
  @@registered_checkers = Set.new
end

.run(sourcefile) ⇒ Object

run the checks on source



21
22
23
24
25
# File 'lib/codeqa/runner.rb', line 21

def self.run(sourcefile)
  runner = new(sourcefile)
  runner.run
  runner
end

Instance Method Details

#display_result(options = {}) ⇒ Object



57
58
59
# File 'lib/codeqa/runner.rb', line 57

def display_result(options={})
  RunnerDecorator.new(self, options)
end

#failuresObject



49
50
51
# File 'lib/codeqa/runner.rb', line 49

def failures
  @failures ||= @results.reject(&:success?)
end

#runObject



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

def run
  return @results unless @results.empty?
  @results = @@registered_checkers.map do |checker_klass|
    next unless checker_klass.check?(sourcefile)
    checker = checker_klass.new(sourcefile)

    checker.before_check if checker.respond_to?(:before_check)
    checker.check
    checker.after_check if checker.respond_to?(:after_check)
    checker
  end.compact
end

#success?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/codeqa/runner.rb', line 53

def success?
  failures.empty?
end