class Noticent::Definitions::Hooks

Constants

VALID_STEPS

Public Instance Methods

add(step, klass) click to toggle source
# File lib/noticent/definitions/hooks.rb, line 8
def add(step, klass)
  raise BadConfiguration, "invalid step. valid values are #{VALID_STEPS}" unless VALID_STEPS.include? step
  raise BadConfiguration, "hook #{klass} doesn't have a #{step} method" unless klass.respond_to? step

  storage[step] = [] if storage[step].nil?
  storage[step] << klass
end
fetch(step) click to toggle source
# File lib/noticent/definitions/hooks.rb, line 16
def fetch(step)
  raise ::ArgumentError, "invalid step. valid values are #{VALID_STEPS}" unless VALID_STEPS.include? step

  storage[step]
end
run(step, chan) click to toggle source
# File lib/noticent/definitions/hooks.rb, line 22
def run(step, chan)
  chain = fetch(step)
  return if chain.nil?

  chain.each do |to_run|
    to_run.send(step, chan) if to_run.respond_to? step
  end
end

Private Instance Methods

storage() click to toggle source
# File lib/noticent/definitions/hooks.rb, line 33
def storage
  @storage ||= {}
end