class SugarCane::Runner

Orchestrates the running of checks per the provided configuration, and hands the result to a formatter for display. This is the core of the application, but for the actual entry point see `SugarCane::CLI`.

Attributes

checks[R]
opts[R]

Public Class Methods

new(spec) click to toggle source
# File lib/sugarcane/runner.rb, line 18
def initialize(spec)
  @opts = spec
  @checks = spec[:checks]
end

Public Instance Methods

run() click to toggle source
# File lib/sugarcane/runner.rb, line 23
def run
  check_options(violations, opts)
  violations.length <= opts.fetch(:max_violations)
end

Protected Instance Methods

check_options(violations, opts) click to toggle source
# File lib/sugarcane/runner.rb, line 44
def check_options(violations, opts)
  if opts[:report]
    outputter.print ViolationFormatter.new(violations, opts)
  elsif opts[:json]
    outputter.print JsonFormatter.new(violations, opts)
  else
    menu = SugarCane::Menu.new(@checks, @opts)
    menu.run
  end
end
check_violations() click to toggle source
# File lib/sugarcane/runner.rb, line 38
def check_violations
  @violations = checks.
    map { |check| check.new(opts).violations }.
    flatten
end
outputter() click to toggle source
# File lib/sugarcane/runner.rb, line 55
def outputter
  opts.fetch(:out, $stdout)
end
violations() click to toggle source
# File lib/sugarcane/runner.rb, line 32
def violations
  @violations ||= checks.
    map { |check| check.new(opts).violations }.
    flatten
end