Class: PreCommit::Runner
- Inherits:
-
Object
- Object
- PreCommit::Runner
- Includes:
- Utils::StagedFiles
- Defined in:
- lib/pre-commit/runner.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#pluginator ⇒ Object
readonly
Returns the value of attribute pluginator.
Instance Method Summary collapse
- #checks(list) ⇒ Object
- #execute(list) ⇒ Object
-
#initialize(stderr = nil, staged_files = nil, config = nil, pluginator = nil) ⇒ Runner
constructor
A new instance of Runner.
- #list_evaluator ⇒ Object
- #list_to_run(name) ⇒ Object
- #run ⇒ Object
- #run_single(name) ⇒ Object
- #show_output(name, list) ⇒ Object
- #warnings(list) ⇒ Object
Methods included from Utils::StagedFiles
Constructor Details
#initialize(stderr = nil, staged_files = nil, config = nil, pluginator = nil) ⇒ Runner
Returns a new instance of 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
#config ⇒ Object (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/pre-commit/runner.rb', line 10 def config @config end |
#pluginator ⇒ Object (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
56 57 58 59 60 61 62 63 |
# File 'lib/pre-commit/runner.rb', line 56 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
37 38 39 |
# File 'lib/pre-commit/runner.rb', line 37 def execute(list) list.map{|cmd| cmd.new(pluginator, config, list).call(staged_files.dup) }.compact end |
#list_evaluator ⇒ Object
45 46 47 |
# File 'lib/pre-commit/runner.rb', line 45 def list_evaluator @list_evaluator ||= PreCommit::ListEvaluator.new(config) end |
#list_to_run(name) ⇒ Object
41 42 43 |
# File 'lib/pre-commit/runner.rb', line 41 def list_to_run(name) list_evaluator.send(:"#{name}_evaluated", :list_to_run) end |
#run ⇒ Object
19 20 21 22 23 |
# File 'lib/pre-commit/runner.rb', line 19 def run run_single(:warnings) run_single(:checks ) or return false true end |
#run_single(name) ⇒ Object
25 26 27 |
# File 'lib/pre-commit/runner.rb', line 25 def run_single(name) show_output(name, execute(list_to_run(name))) end |
#show_output(name, list) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/pre-commit/runner.rb', line 29 def show_output(name, list) if list.any? @stderr.puts send(name, list) return false end true end |
#warnings(list) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/pre-commit/runner.rb', line 49 def warnings(list) <<-WARNINGS pre-commit: Some warnings were raised. These will not stop commit: #{list.join("\n")} WARNINGS end |