Class: PreCommit::Runner
Instance Attribute Summary collapse
Instance Method Summary
collapse
#set_staged_files, #staged_files, #staged_files=, #staged_files_all, #staged_files_git_all
Constructor Details
#initialize(stderr = nil, staged_files = nil, config = nil, pluginator = nil) ⇒ Runner
Returns a new instance of Runner.
14
15
16
17
18
19
20
|
# File 'lib/pre-commit/runner.rb', line 14
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
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
12
13
14
|
# File 'lib/pre-commit/runner.rb', line 12
def config
@config
end
|
#debug ⇒ Object
Returns the value of attribute debug.
12
13
14
|
# File 'lib/pre-commit/runner.rb', line 12
def debug
@debug
end
|
#pluginator ⇒ Object
Returns the value of attribute pluginator.
12
13
14
|
# File 'lib/pre-commit/runner.rb', line 12
def pluginator
@pluginator
end
|
Instance Method Details
#checks(list) ⇒ Object
70
71
72
73
74
75
76
77
|
# File 'lib/pre-commit/runner.rb', line 70
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
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/pre-commit/runner.rb', line 41
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 ⇒ Object
59
60
61
|
# File 'lib/pre-commit/runner.rb', line 59
def list_evaluator
@list_evaluator ||= PreCommit::ListEvaluator.new(config)
end
|
#list_to_run(name) ⇒ Object
55
56
57
|
# File 'lib/pre-commit/runner.rb', line 55
def list_to_run(name)
list_evaluator.send(:"#{name}_evaluated", :list_to_run)
end
|
#run(*args) ⇒ Object
22
23
24
25
26
27
|
# File 'lib/pre-commit/runner.rb', line 22
def run(*args)
set_staged_files(*args)
run_single(:warnings)
run_single(:checks ) or return false
true
end
|
#run_single(name) ⇒ Object
29
30
31
|
# File 'lib/pre-commit/runner.rb', line 29
def run_single(name)
show_output(name, execute(list_to_run(name)))
end
|
#show_output(name, list) ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/pre-commit/runner.rb', line 33
def show_output(name, list)
if list.any?
@stderr.puts send(name, list)
return false
end
true
end
|
#warnings(list) ⇒ Object
63
64
65
66
67
68
|
# File 'lib/pre-commit/runner.rb', line 63
def warnings(list)
<<-WARNINGS
pre-commit: Some warnings were raised. These will not stop commit:
#{list.join("\n")}
WARNINGS
end
|