Class: Overcommit::HookRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/overcommit/hook_runner.rb

Overview

Responsible for loading the hooks the repository has configured and running them, collecting and displaying the results.

Instance Method Summary collapse

Constructor Details

#initialize(config, logger, context, printer) ⇒ HookRunner

Returns a new instance of HookRunner.



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

def initialize(config, logger, context, printer)
  @config = config
  @log = logger
  @context = context
  @printer = printer
  @hooks = []
end

Instance Method Details

#runObject

Loads and runs the hooks registered for this Overcommit::HookRunner.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/overcommit/hook_runner.rb', line 18

def run
  # ASSUMPTION: we assume the setup and cleanup calls will never need to be
  # interrupted, i.e. they will finish quickly. Should further evidence
  # suggest this assumption does not hold, we will have to separately wrap
  # these calls to allow some sort of "are you sure?" double-interrupt
  # functionality, but until that's deemed necessary let's keep it simple.
  InterruptHandler.isolate_from_interrupts do
    @context.setup_environment
    load_hooks
    result = run_hooks
    @context.cleanup_environment
    result
  end
end