Class: Overcommit::Printer
- Inherits:
-
Object
- Object
- Overcommit::Printer
- Defined in:
- lib/overcommit/printer.rb
Overview
Provide a set of callbacks which can be executed as events occur during the course of HookRunner#run.
Instance Attribute Summary collapse
-
#log ⇒ Object
readonly
Returns the value of attribute log.
Instance Method Summary collapse
-
#end_hook(hook, status, output) ⇒ Object
Executed at the end of an individual hook run.
- #hook_skipped(hook) ⇒ Object
-
#initialize(logger, context) ⇒ Printer
constructor
A new instance of Printer.
- #nothing_to_run ⇒ Object
- #required_hook_not_skipped(hook) ⇒ Object
-
#run_failed ⇒ Object
Executed when one or more hooks by the end of the run.
-
#run_interrupted ⇒ Object
Executed when a hook run was interrupted/cancelled by user.
-
#run_succeeded ⇒ Object
Executed when no hooks failed by the end of the run.
-
#run_warned ⇒ Object
Executed when no hooks failed by the end of the run, but some warned.
-
#start_hook(hook) ⇒ Object
Executed at the start of an individual hook run.
-
#start_run ⇒ Object
Executed at the very beginning of running the collection of hooks.
Constructor Details
#initialize(logger, context) ⇒ Printer
Returns a new instance of Printer.
9 10 11 12 |
# File 'lib/overcommit/printer.rb', line 9 def initialize(logger, context) @log = logger @context = context end |
Instance Attribute Details
#log ⇒ Object (readonly)
Returns the value of attribute log.
7 8 9 |
# File 'lib/overcommit/printer.rb', line 7 def log @log end |
Instance Method Details
#end_hook(hook, status, output) ⇒ Object
Executed at the end of an individual hook run.
39 40 41 42 43 44 45 |
# File 'lib/overcommit/printer.rb', line 39 def end_hook(hook, status, output) # Want to print the header for quiet hooks only if the result wasn't good # so that the user knows what failed print_header(hook) if hook.quiet? && status != :pass print_result(hook, status, output) end |
#hook_skipped(hook) ⇒ Object
30 31 32 |
# File 'lib/overcommit/printer.rb', line 30 def hook_skipped(hook) log.warning "Skipping #{hook.name}" end |
#nothing_to_run ⇒ Object
19 20 21 |
# File 'lib/overcommit/printer.rb', line 19 def nothing_to_run log.debug "✓ No applicable #{hook_script_name} hooks to run" end |
#required_hook_not_skipped(hook) ⇒ Object
34 35 36 |
# File 'lib/overcommit/printer.rb', line 34 def required_hook_not_skipped(hook) log.warning "Cannot skip #{hook.name} since it is required" end |
#run_failed ⇒ Object
Executed when one or more hooks by the end of the run.
55 56 57 58 59 |
# File 'lib/overcommit/printer.rb', line 55 def run_failed log.newline log.error "✗ One or more #{hook_script_name} hooks failed" log.newline end |
#run_interrupted ⇒ Object
Executed when a hook run was interrupted/cancelled by user.
48 49 50 51 52 |
# File 'lib/overcommit/printer.rb', line 48 def run_interrupted log.newline log.warning '⚠ Hook run interrupted by user' log.newline end |
#run_succeeded ⇒ Object
Executed when no hooks failed by the end of the run.
69 70 71 72 73 |
# File 'lib/overcommit/printer.rb', line 69 def run_succeeded log.newline log.success "✓ All #{hook_script_name} hooks passed" log.newline end |
#run_warned ⇒ Object
Executed when no hooks failed by the end of the run, but some warned.
62 63 64 65 66 |
# File 'lib/overcommit/printer.rb', line 62 def run_warned log.newline log.warning "⚠ All #{hook_script_name} hooks passed, but with warnings" log.newline end |
#start_hook(hook) ⇒ Object
Executed at the start of an individual hook run.
24 25 26 27 28 |
# File 'lib/overcommit/printer.rb', line 24 def start_hook(hook) unless hook.quiet? print_header(hook) end end |
#start_run ⇒ Object
Executed at the very beginning of running the collection of hooks.
15 16 17 |
# File 'lib/overcommit/printer.rb', line 15 def start_run log.bold "Running #{hook_script_name} hooks" end |