Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract runner to own file, requiring cane loads up all classes.
- Loading branch information
1 parent
10568b9
commit dac4ded
Showing
4 changed files
with
44 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,2 @@ | ||
require 'parallel' | ||
|
||
require 'cane/violation_formatter' | ||
|
||
module Cane | ||
def run(*args) | ||
Runner.new(*args).run | ||
end | ||
module_function :run | ||
|
||
# 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 `Cane::CLI`. | ||
class Runner | ||
def initialize(spec) | ||
@opts = spec | ||
@checks = spec[:checks] | ||
end | ||
|
||
def run | ||
outputter.print ViolationFormatter.new(violations) | ||
|
||
violations.length <= opts.fetch(:max_violations) | ||
end | ||
|
||
protected | ||
|
||
attr_reader :opts, :checks | ||
|
||
def violations | ||
@violations ||= checks. | ||
map {|check| check.new(opts).violations }. | ||
flatten | ||
end | ||
|
||
def outputter | ||
opts.fetch(:out, $stdout) | ||
end | ||
end | ||
end | ||
require 'cane/cli' | ||
require 'cane/version' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
require 'cane' | ||
require 'cane/runner' | ||
require 'cane/version' | ||
|
||
require 'cane/cli/parser' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require 'parallel' | ||
|
||
require 'cane/violation_formatter' | ||
|
||
module Cane | ||
def run(*args) | ||
Runner.new(*args).run | ||
end | ||
module_function :run | ||
|
||
# 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 `Cane::CLI`. | ||
class Runner | ||
def initialize(spec) | ||
@opts = spec | ||
@checks = spec[:checks] | ||
end | ||
|
||
def run | ||
outputter.print ViolationFormatter.new(violations) | ||
|
||
violations.length <= opts.fetch(:max_violations) | ||
end | ||
|
||
protected | ||
|
||
attr_reader :opts, :checks | ||
|
||
def violations | ||
@violations ||= checks. | ||
map {|check| check.new(opts).violations }. | ||
flatten | ||
end | ||
|
||
def outputter | ||
opts.fetch(:out, $stdout) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
require 'spec_helper' | ||
|
||
require 'cane' | ||
require 'cane/runner' | ||
|
||
describe Cane::Runner do | ||
describe '#run' do | ||
|