class Paradeiser::Hook

Public Class Methods

new(phase) click to toggle source
# File lib/paradeiser/models/hook.rb, line 3
def initialize(phase)
  @phase = phase
end

Public Instance Methods

execute(pom, event) click to toggle source
# 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

Private Instance Methods

hook(name) click to toggle source
# File lib/paradeiser/models/hook.rb, line 26
def hook(name)
  File.join(Paradeiser.hooks_dir, name)
end