module Sequel::Plugins::InstanceHooks::InstanceMethods

Constants

AFTER_HOOKS
BEFORE_HOOKS
HOOKS

Private Instance Methods

add_instance_hook(hook, &block) click to toggle source

Add the block as an instance level hook. For before hooks, add it to the beginning of the instance hook's array. For after hooks, add it to the end.

# File lib/sequel/plugins/instance_hooks.rb, line 55
def add_instance_hook(hook, &block)
  instance_hooks(hook).send(BEFORE_HOOKS.include?(hook) ? :unshift : :push, block)
end
instance_hooks(hook) click to toggle source

An array of instance level hook blocks for the given hook type.

# File lib/sequel/plugins/instance_hooks.rb, line 60
def instance_hooks(hook)
  @instance_hooks ||= {}
  @instance_hooks[hook] ||= []
end
run_after_instance_hooks(hook) click to toggle source

Run all hook blocks of the given hook type.

# File lib/sequel/plugins/instance_hooks.rb, line 66
def run_after_instance_hooks(hook)
  instance_hooks(hook).each{|b| b.call}
end
run_before_instance_hooks(hook) click to toggle source

Run all hook blocks of the given hook type. If a hook block returns false, immediately return false without running the remaining blocks.

# File lib/sequel/plugins/instance_hooks.rb, line 72
def run_before_instance_hooks(hook)
  instance_hooks(hook).each{|b| return false if b.call == false}
end