module Sequel::Plugins::HookClassMethods::ClassMethods
Public Instance Methods
freeze()
click to toggle source
Freeze hooks when freezing model class.
Calls superclass method
# File lib/sequel/plugins/hook_class_methods.rb, line 49 def freeze @hooks.freeze.each_value(&:freeze) super end
has_hooks?(hook)
click to toggle source
Returns true if there are any hook blocks for the given hook.
# File lib/sequel/plugins/hook_class_methods.rb, line 55 def has_hooks?(hook) !@hooks[hook].empty? end
hook_blocks(hook) { |v| ... }
click to toggle source
Yield every block related to the given hook.
# File lib/sequel/plugins/hook_class_methods.rb, line 60 def hook_blocks(hook) @hooks[hook].each{|k,v| yield v} end
Private Instance Methods
add_hook(hook, tag, &block)
click to toggle source
Add a hook block to the list of hook methods. If a non-nil tag is given and it already is in the list of hooks, replace it with the new block.
# File lib/sequel/plugins/hook_class_methods.rb, line 71 def add_hook(hook, tag, &block) unless block (raise Error, 'No hook method specified') unless tag # Allow calling private hook methods block = proc {send(tag)} end h = @hooks[hook] if tag && (old = h.find{|x| x[0] == tag}) old[1] = block else if hook.to_s =~ /^before/ h.unshift([tag,block]) else h << [tag, block] end end end