Class: SuperHooks::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/super_hooks/runner.rb

Overview

Class responsible for running the hooks and reporting on status

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hook, arguments) ⇒ Runner

Prepare for a new commit runner check

  • hook: the hook name wer’re about to run

  • arguments: the arguments past to the hook



15
16
17
18
# File 'lib/super_hooks/runner.rb', line 15

def initialize(hook, arguments)
  @hooks = Hook.where(kind: [hook])
  @arguments = arguments
end

Instance Attribute Details

#argumentsObject (readonly)

arguments passed by git when running a hook



8
9
10
# File 'lib/super_hooks/runner.rb', line 8

def arguments
  @arguments
end

#hooksObject (readonly)

the hooks one would like to run



5
6
7
# File 'lib/super_hooks/runner.rb', line 5

def hooks
  @hooks
end

Instance Method Details

#runObject

Run all the associated hooks

Exit the program with a bad status if any of the hooks fail



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/super_hooks/runner.rb', line 24

def run
  failed_hooks = []
  hooks.each do |hook|
    failed_hooks << hook unless hook.execute!(arguments)
  end

  unless failed_hooks.empty?
    $stderr.puts "Hooks #{failed_hooks.map(&:path).join(', ')} failed to exit successfully"
    exit 1
  end
end