module Sequel::Plugins::InstanceHooks::InstanceMethods
Public Instance Methods
after_destroy()
click to toggle source
Run after destroy instance hooks.
Calls superclass method
# 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
after_save()
click to toggle source
Run after save instance hooks.
Calls superclass method
# 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
after_validation()
click to toggle source
Run after validation instance hooks.
Calls superclass method
# File lib/sequel/plugins/instance_hooks.rb, line 61 def after_validation super return unless @instance_hooks run_after_instance_hooks(:after_validation) end
before_destroy()
click to toggle source
Run #before_destroy instance hooks.
Calls superclass method
# 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
before_save()
click to toggle source
Run #before_save instance hooks.
Calls superclass method
# 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
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 97 def add_instance_hook(hook, &block) instance_hooks(hook).public_send(hook.to_s.start_with?('before') ? :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 102 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 108 def run_after_instance_hooks(hook) instance_hooks(hook).each(&:call) end
Also aliased as: run_before_instance_hooks