Class: PreCommit::Runner

Inherits:
Object
  • Object
show all
Includes:
Utils::StagedFiles
Defined in:
lib/pre-commit/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::StagedFiles

#set_staged_files, #staged_files, #staged_files=, #staged_files_all

Constructor Details

#initialize(stderr = nil, staged_files = nil, config = nil, pluginator = nil) ⇒ Runner



12
13
14
15
16
17
# File 'lib/pre-commit/runner.rb', line 12

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
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/pre-commit/runner.rb', line 10

def config
  @config
end

#pluginatorObject (readonly)

Returns the value of attribute pluginator.



10
11
12
# File 'lib/pre-commit/runner.rb', line 10

def pluginator
  @pluginator
end

Instance Method Details

#checks(list) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/pre-commit/runner.rb', line 57

def checks(list)
  <<-ERRORS
pre-commit: Stopping commit because of errors.
#{list.join("\n")}
pre-commit: You can bypass this check using `git commit -n`

ERRORS
end

#execute(list) ⇒ Object



38
39
40
# File 'lib/pre-commit/runner.rb', line 38

def execute(list)
  list.map{|cmd| cmd.new(pluginator, config, list).call(staged_files.dup) }.compact
end

#list_evaluatorObject



46
47
48
# File 'lib/pre-commit/runner.rb', line 46

def list_evaluator
  @list_evaluator ||= PreCommit::ListEvaluator.new(config)
end

#list_to_run(name) ⇒ Object



42
43
44
# File 'lib/pre-commit/runner.rb', line 42

def list_to_run(name)
  list_evaluator.send(:"#{name}_evaluated", :list_to_run)
end

#run(*args) ⇒ Object



19
20
21
22
23
24
# File 'lib/pre-commit/runner.rb', line 19

def run(*args)
  set_staged_files(*args)
  run_single(:warnings)
  run_single(:checks  ) or return false
  true
end

#run_single(name) ⇒ Object



26
27
28
# File 'lib/pre-commit/runner.rb', line 26

def run_single(name)
  show_output(name, execute(list_to_run(name)))
end

#show_output(name, list) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/pre-commit/runner.rb', line 30

def show_output(name, list)
  if list.any?
    @stderr.puts send(name, list)
    return false
  end
  true
end

#warnings(list) ⇒ Object



50
51
52
53
54
55
# File 'lib/pre-commit/runner.rb', line 50

def warnings(list)
  <<-WARNINGS
pre-commit: Some warnings were raised. These will not stop commit:
#{list.join("\n")}
WARNINGS
end