Navigation Menu

Skip to content

Commit

Permalink
Extract runner to own file, requiring cane loads up all classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviershay committed Sep 16, 2012
1 parent 10568b9 commit dac4ded
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 42 deletions.
42 changes: 2 additions & 40 deletions lib/cane.rb
@@ -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'
2 changes: 1 addition & 1 deletion lib/cane/cli.rb
@@ -1,4 +1,4 @@
require 'cane'
require 'cane/runner'
require 'cane/version'

require 'cane/cli/parser'
Expand Down
40 changes: 40 additions & 0 deletions lib/cane/runner.rb
@@ -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
2 changes: 1 addition & 1 deletion spec/runner_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'

require 'cane'
require 'cane/runner'

describe Cane::Runner do
describe '#run' do
Expand Down

0 comments on commit dac4ded

Please sign in to comment.