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.



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

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



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

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? && ![:good, :pass].include?(status)

  print_result(hook, status, output)
end

#end_run(run_failed, interrupted) ⇒ Object

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



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/overcommit/printer.rb', line 24

def end_run(run_failed, interrupted)
  log.log # Newline

  if interrupted
    log.warning '⚠  Hook run interrupted by user'
  elsif run_failed
    log.error "✗ One or more #{hook_script_name} hooks failed"
  else
    log.success "✓ All #{hook_script_name} hooks passed"
  end

  log.log # Newline
end

#hook_skipped(hook) ⇒ Object



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

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

#nothing_to_runObject



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

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

#required_hook_not_skipped(hook) ⇒ Object



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

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

#start_hook(hook) ⇒ Object

Executed at the start of an individual hook run.



39
40
41
42
43
# File 'lib/overcommit/printer.rb', line 39

def start_hook(hook)
  unless hook.quiet?
    print_header(hook)
  end
end

#start_runObject

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