module Runbook::Hooks

Public Instance Methods

_hook_index(hook_name) click to toggle source
# File lib/runbook/hooks.rb, line 28
def _hook_index(hook_name)
  hooks.index { |hook| hook[:name] == hook_name } || -1
end
hooks() click to toggle source
# File lib/runbook/hooks.rb, line 3
def hooks
  @hooks ||= []
end
hooks_for(type, klass) click to toggle source
# File lib/runbook/hooks.rb, line 22
def hooks_for(type, klass)
  hooks.select do |hook|
    hook[:type] == type && klass <= hook[:klass]
  end
end
register_hook(name, type, klass, before: nil, &block) click to toggle source
# File lib/runbook/hooks.rb, line 7
def register_hook(name, type, klass, before: nil, &block)
  hook = {
    name: name,
    type: type,
    klass: klass,
    block: block,
  }

  if before
    hooks.insert(_hook_index(before), hook)
  else
    hooks << hook
  end
end