module Sequel::Plugins::InstanceHooks::InstanceMethods

Constants

AFTER_HOOKS
BEFORE_HOOKS
HOOKS

Public Instance Methods

after_save() click to toggle source

Run after save hooks, clearing both the save and validation hooks.

Calls superclass method
# File lib/sequel/plugins/instance_hooks.rb, line 59
def after_save
  super
  run_after_instance_hooks(:after_save)
  @instance_hooks.delete(:after_save)
  @instance_hooks.delete(:before_save)
  @instance_hooks.delete(:after_validation)
  @instance_hooks.delete(:before_validation)
end
after_validation() click to toggle source

Run after validation hooks, without clearing the validation hooks.

Calls superclass method
# File lib/sequel/plugins/instance_hooks.rb, line 53
def after_validation
  super
  run_after_instance_hooks(:after_validation)
end

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 73
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 78
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 84
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 90
def run_before_instance_hooks(hook)
  instance_hooks(hook).each{|b| return false if b.call == false}
end