Class: Koality::Runner::Cane
- Inherits:
-
Object
- Object
- Koality::Runner::Cane
- Defined in:
- lib/koality/runner/cane.rb
Instance Attribute Summary collapse
-
#cane_options ⇒ Object
readonly
Returns the value of attribute cane_options.
-
#violations ⇒ Object
readonly
Returns the value of attribute violations.
Instance Method Summary collapse
- #checkers ⇒ Object
- #exceeds_total_violations_threshold? ⇒ Boolean
- #exceeds_violations_threshold?(type) ⇒ Boolean
-
#initialize(options) ⇒ Cane
constructor
A new instance of Cane.
- #run ⇒ Object
- #run_checker(type) ⇒ Object
- #success? ⇒ Boolean
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() @cane_options = () @violations = {} end |
Instance Attribute Details
#cane_options ⇒ Object (readonly)
Returns the value of attribute cane_options.
7 8 9 |
# File 'lib/koality/runner/cane.rb', line 7 def @cane_options end |
#violations ⇒ Object (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
#checkers ⇒ Object
20 21 22 |
# File 'lib/koality/runner/cane.rb', line 20 def checkers ::Cane::Runner::CHECKERS.select { |type, _| .key?(type) } end |
#exceeds_total_violations_threshold? ⇒ Boolean
38 39 40 41 42 43 |
# File 'lib/koality/runner/cane.rb', line 38 def exceeds_total_violations_threshold? max_violations = Koality..total_violations_threshold total_violations = violations.values.flatten.count max_violations >= 0 && total_violations > max_violations end |
#exceeds_violations_threshold?(type) ⇒ Boolean
45 46 47 48 49 50 |
# File 'lib/koality/runner/cane.rb', line 45 def exceeds_violations_threshold?(type) max_violations = Koality.[:"#{type}_violations_threshold"].to_i total_violations = violations[type].count max_violations >= 0 && total_violations > max_violations end |
#run ⇒ Object
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([type]) self.violations[type] = checker.violations reporter.report(type, violations[type]) end end |
#success? ⇒ 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 |