class PreCommit::Runner

Attributes

config[R]
debug[R]
pluginator[R]

Public Class Methods

new(stderr = nil, staged_files = nil, config = nil, pluginator = nil) click to toggle source
# File lib/pre-commit/runner.rb, line 15
def initialize(stderr = nil, staged_files = nil, config = nil, pluginator = nil)
  @stderr       = (stderr       or $stderr)
  @pluginator   = (pluginator   or PreCommit.pluginator)
  @config       = (config       or PreCommit::Configuration.new(@pluginator))
  @staged_files = staged_files
  @debug = ENV["PRE_COMMIT_DEBUG"]
end

Public Instance Methods

checks(list) click to toggle source
# File lib/pre-commit/runner.rb, line 71
    def checks(list)
      <<-ERRORS
pre-commit: Stopping commit because of errors.
#{errors_to_string(list)}
pre-commit: You can bypass this check using `git commit -n`

ERRORS
    end
errors_to_string(list) click to toggle source
# File lib/pre-commit/runner.rb, line 80
def errors_to_string(list)
  list.map(&:to_s).join("\n")
end
execute(list) click to toggle source
# File lib/pre-commit/runner.rb, line 42
def execute(list)
  list.map do |cmd|
    result = nil

    seconds = Benchmark.realtime do
      result = cmd.new(pluginator, config, list).call(staged_files.dup)
    end

    puts "#{cmd} #{seconds*1000}ms" if debug

    result
  end.compact
end
list_evaluator() click to toggle source
# File lib/pre-commit/runner.rb, line 60
def list_evaluator
  @list_evaluator ||= PreCommit::ListEvaluator.new(config)
end
list_to_run(name) click to toggle source
# File lib/pre-commit/runner.rb, line 56
def list_to_run(name)
  list_evaluator.send(:"#{name}_evaluated", :list_to_run)
end
run(*args) click to toggle source
# File lib/pre-commit/runner.rb, line 23
def run(*args)
  set_staged_files(*args)
  run_single(:warnings)
  run_single(:checks  ) or return false
  true
end
run_single(name) click to toggle source
# File lib/pre-commit/runner.rb, line 30
def run_single(name)
  show_output(name, execute(list_to_run(name)))
end
show_output(name, list) click to toggle source
# File lib/pre-commit/runner.rb, line 34
def show_output(name, list)
  if list.any?
    @stderr.puts send(name, list)
    return false
  end
  true
end
warnings(list) click to toggle source
# File lib/pre-commit/runner.rb, line 64
    def warnings(list)
      <<-WARNINGS
pre-commit: Some warnings were raised. These will not stop commit:
#{errors_to_string(list)}
WARNINGS
    end