Class: Overcommit::Printer

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(logger, context) ⇒ Printer

Returns a new instance of Printer.



11
12
13
14
15
16
# File 'lib/overcommit/printer.rb', line 11

def initialize(logger, context)
  @log = logger
  @context = context
  @lock = Monitor.new # Need to use monitor so we can have re-entrant locks
  synchronize_all_methods
end

Instance Attribute Details

#logObject (readonly)

Returns the value of attribute log.



9
10
11
# File 'lib/overcommit/printer.rb', line 9

def log
  @log
end

Instance Method Details

#end_hook(hook, status, output) ⇒ Object

Executed at the end of an individual hook run.



36
37
38
39
40
41
42
# File 'lib/overcommit/printer.rb', line 36

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



27
28
29
# File 'lib/overcommit/printer.rb', line 27

def hook_skipped(hook)
  log.warning "Skipping #{hook.name}"
end

#interrupt_triggeredObject



44
45
46
47
# File 'lib/overcommit/printer.rb', line 44

def interrupt_triggered
  log.newline
  log.error 'Interrupt signal received. Stopping hooks...'
end

#nothing_to_runObject



23
24
25
# File 'lib/overcommit/printer.rb', line 23

def nothing_to_run
  log.debug "✓ No applicable #{hook_script_name} hooks to run"
end

#required_hook_not_skipped(hook) ⇒ Object



31
32
33
# File 'lib/overcommit/printer.rb', line 31

def required_hook_not_skipped(hook)
  log.warning "Cannot skip #{hook.name} since it is required"
end

#run_failedObject

Executed when one or more hooks by the end of the run.



57
58
59
60
61
# File 'lib/overcommit/printer.rb', line 57

def run_failed
  log.newline
  log.error "✗ One or more #{hook_script_name} hooks failed"
  log.newline
end

#run_interruptedObject

Executed when a hook run was interrupted/cancelled by user.



50
51
52
53
54
# File 'lib/overcommit/printer.rb', line 50

def run_interrupted
  log.newline
  log.warning '⚠  Hook run interrupted by user'
  log.newline
end

#run_succeededObject

Executed when no hooks failed by the end of the run.



71
72
73
74
75
# File 'lib/overcommit/printer.rb', line 71

def run_succeeded
  log.newline
  log.success "✓ All #{hook_script_name} hooks passed"
  log.newline
end

#run_warnedObject

Executed when no hooks failed by the end of the run, but some warned.



64
65
66
67
68
# File 'lib/overcommit/printer.rb', line 64

def run_warned
  log.newline
  log.warning "⚠ All #{hook_script_name} hooks passed, but with warnings"
  log.newline
end

#start_runObject

Executed at the very beginning of running the collection of hooks.



19
20
21
# File 'lib/overcommit/printer.rb', line 19

def start_run
  log.bold "Running #{hook_script_name} hooks"
end