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(config, logger, context) ⇒ Printer


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

def initialize(config, logger, context)
  @config = config
  @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


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.


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

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? && !@config['quiet']) || status != :pass

  print_result(hook, status, output)
end

#hook_run_failed(message) ⇒ Object


78
79
80
81
82
# File 'lib/overcommit/printer.rb', line 78

def hook_run_failed(message)
  log.newline
  log.log message
  log.newline
end

#hook_skipped(hook) ⇒ Object


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

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

#interrupt_triggeredObject


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

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

#nothing_to_runObject


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

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

#required_hook_not_skipped(hook) ⇒ Object


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

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.


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

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.


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

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.


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

def run_succeeded
  unless @config['quiet']
    log.newline
    log.success "✓ All #{hook_script_name} hooks passed"
    log.newline
  end
end

#run_warnedObject

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


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

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.


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

def start_run
  log.bold "Running #{hook_script_name} hooks" unless @config['quiet']
end