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
50 def freeze
51   @hooks.freeze.each_value(&:freeze)
52   super
53 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
56 def has_hooks?(hook)
57   !@hooks[hook].empty?
58 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
61 def hook_blocks(hook)
62   @hooks[hook].each{|k,v| yield v}
63 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
72 def add_hook(hook, tag, &block)
73   unless block
74     (raise Error, 'No hook method specified') unless tag
75     # Allow calling private hook methods
76     block = proc {send(tag)}
77   end
78   h = @hooks[hook]
79   if tag && (old = h.find{|x| x[0] == tag})
80     old[1] = block
81   else
82     if hook.to_s =~ /^before/
83       h.unshift([tag,block])
84     else
85       h << [tag, block]
86     end
87   end
88 end