Class: Paradeiser::Hook

Inherits:
Object
  • Object
show all
Defined in:
lib/paradeiser/models/hook.rb

Instance Method Summary collapse

Constructor Details

#initialize(phase) ⇒ Hook

Returns a new instance of Hook.



3
4
5
# File 'lib/paradeiser/models/hook.rb', line 3

def initialize(phase)
  @phase = phase
end

Instance Method Details

#execute(pom, event) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/paradeiser/models/hook.rb', line 7

def execute(pom, event)
  name = "#{@phase}-#{event}-#{pom.name}"
  hook = hook(name)

  if File.exist?(hook) && File.executable?(hook)
    ENV["PAR_#{pom.name.upcase}_ID"] = pom.id ? pom.id.to_s : Repository.next_id.to_s
    ENV["PAR_#{pom.name.upcase}_STARTED_AT"] = pom.started_at.strftime('%H:%M') if pom.started_at

    out, err, status = Open3.capture3(hook)

    ENV.delete("PAR_#{pom.name.upcase}_ID")
    ENV.delete("PAR_#{pom.name.upcase}_STARTED_AT")

    raise HookFailedError.new(hook, out, err, status) if 0 != status.exitstatus
  end
end