Run after destroy instance hooks.
# File lib/sequel/plugins/instance_hooks.rb, line 52 def after_destroy super return unless @instance_hooks run_after_instance_hooks(:after_destroy) @instance_hooks.delete(:after_destroy) @instance_hooks.delete(:before_destroy) end
Run after save instance hooks.
# File lib/sequel/plugins/instance_hooks.rb, line 68 def after_save super return unless @instance_hooks 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 instance hooks.
# File lib/sequel/plugins/instance_hooks.rb, line 61 def after_validation super return unless @instance_hooks run_after_instance_hooks(:after_validation) end
Run #before_destroy instance hooks.
# File lib/sequel/plugins/instance_hooks.rb, line 79 def before_destroy return super unless @instance_hooks run_before_instance_hooks(:before_destroy) super end
Run #before_save instance hooks.
# File lib/sequel/plugins/instance_hooks.rb, line 86 def before_save return super unless @instance_hooks run_before_instance_hooks(:before_save) super 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 97 def add_instance_hook(hook, &block) instance_hooks(hook).public_send(hook.to_s.start_with?('before') ? :unshift : :push, block) end
An array of instance level hook blocks for the given hook type.
# File lib/sequel/plugins/instance_hooks.rb, line 102 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 108 def run_after_instance_hooks(hook) instance_hooks(hook).each(&:call) end