Class: Koality::Runner::Cane

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Cane

Returns a new instance of Cane.



9
10
11
12
# File 'lib/koality/runner/cane.rb', line 9

def initialize(options)
  @cane_options = translate_options(options)
  @violations = {}
end

Instance Attribute Details

#cane_optionsObject (readonly)

Returns the value of attribute cane_options.



7
8
9
# File 'lib/koality/runner/cane.rb', line 7

def cane_options
  @cane_options
end

#violationsObject (readonly)

Returns the value of attribute violations.



7
8
9
# File 'lib/koality/runner/cane.rb', line 7

def violations
  @violations
end

Instance Method Details

#checkersObject



20
21
22
# File 'lib/koality/runner/cane.rb', line 20

def checkers
  ::Cane::Runner::CHECKERS.select { |type, _| cane_options.key?(type) }
end

#exceeds_total_violations_threshold?Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
# File 'lib/koality/runner/cane.rb', line 38

def exceeds_total_violations_threshold?
  max_violations = Koality.options.total_violations_threshold
  total_violations = violations.values.flatten.count

  max_violations >= 0 && total_violations > max_violations
end

#exceeds_violations_threshold?(type) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
48
49
50
# File 'lib/koality/runner/cane.rb', line 45

def exceeds_violations_threshold?(type)
  max_violations = Koality.options[:"#{type}_violations_threshold"].to_i
  total_violations = violations[type].count

  max_violations >= 0 && total_violations > max_violations
end

#runObject



14
15
16
17
18
# File 'lib/koality/runner/cane.rb', line 14

def run
  violations.clear
  checkers.each { |type, _| run_checker(type) }
  success?
end

#run_checker(type) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/koality/runner/cane.rb', line 24

def run_checker(type)
  Koality::Reporter::Cane.start do |reporter|
    checker = checkers[type].new(cane_options[type])
    self.violations[type] = checker.violations

    reporter.report(type, violations[type])
  end
end

#success?Boolean

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/koality/runner/cane.rb', line 33

def success?
  return false if exceeds_total_violations_threshold?
  violations.none? { |type, _| exceeds_violations_threshold?(type) }
end