Freeze hooks when freezing model class.
# File lib/sequel/plugins/hook_class_methods.rb, line 50 def freeze @hooks.freeze.each_value(&:freeze) super end
Returns true if there are any hook blocks for the given hook.
# File lib/sequel/plugins/hook_class_methods.rb, line 56 def has_hooks?(hook) !@hooks[hook].empty? end
Yield every block related to the given hook.
# File lib/sequel/plugins/hook_class_methods.rb, line 61 def hook_blocks(hook) @hooks[hook].each{|k,v| yield v} end
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 72 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