Class: PreCommit::Runner
Constant Summary
Utils::StagedFiles::BINARIES, Utils::StagedFiles::IGNORED_EXTENSIONS, Utils::StagedFiles::IMAGES, Utils::StagedFiles::SOURCE_FILES
Instance Attribute Summary collapse
Instance Method Summary
collapse
#appears_binary?, #ignore_extension?, #repo_ignored?, #set_staged_files, #source_file?, #staged_files, #staged_files=, #staged_files_all, #staged_files_git_all
#top_level
Constructor Details
#initialize(stderr = nil, staged_files = nil, config = nil, pluginator = nil) ⇒ Runner
Returns a new instance of Runner.
15
16
17
18
19
20
21
|
# 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
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
13
14
15
|
# File 'lib/pre-commit/runner.rb', line 13
def config
@config
end
|
#debug ⇒ Object
Returns the value of attribute debug.
13
14
15
|
# File 'lib/pre-commit/runner.rb', line 13
def debug
@debug
end
|
#pluginator ⇒ Object
Returns the value of attribute pluginator.
13
14
15
|
# File 'lib/pre-commit/runner.rb', line 13
def pluginator
@pluginator
end
|
Instance Method Details
#checks(list) ⇒ Object
71
72
73
74
75
76
77
78
|
# 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) ⇒ Object
80
81
82
|
# File 'lib/pre-commit/runner.rb', line 80
def errors_to_string(list)
list.map(&:to_s).join("\n")
end
|
#execute(list) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# 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 ⇒ Object
60
61
62
|
# File 'lib/pre-commit/runner.rb', line 60
def list_evaluator
@list_evaluator ||= PreCommit::ListEvaluator.new(config)
end
|
#list_to_run(name) ⇒ Object
56
57
58
|
# File 'lib/pre-commit/runner.rb', line 56
def list_to_run(name)
list_evaluator.send(:"#{name}_evaluated", :list_to_run)
end
|
#run(*args) ⇒ Object
23
24
25
26
27
28
|
# 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) ⇒ Object
30
31
32
|
# 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) ⇒ Object
34
35
36
37
38
39
40
|
# 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) ⇒ Object
64
65
66
67
68
69
|
# 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
|