Run after save hooks, clearing both the save and validation hooks.
# 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
Run after validation hooks, without clearing the validation hooks.
# File lib/sequel/plugins/instance_hooks.rb, line 53 def after_validation super run_after_instance_hooks(:after_validation) end
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
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 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(&:call) end
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