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   # SEQUEL6: Remove
63   Sequel::Deprecation.deprecate("The hook_blocks class method in the hook_class_methods plugin is deprecated and will be removed in Sequel 6.")
64   @hooks[hook].each{|_,v,_| yield v}
65 end
hook_methods_for(hook) { |m| ... } click to toggle source

Yield every method related to the given hook.

   # File lib/sequel/plugins/hook_class_methods.rb
68 def hook_methods_for(hook)
69   @hooks[hook].each{|_,_,m| yield m}
70 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
79 def add_hook(hook, tag, &block)
80   unless block
81     (raise Error, 'No hook method specified') unless tag
82     # Allow calling private hook methods
83     block = proc {send(tag)}
84   end
85 
86   h = @hooks[hook]
87 
88   if tag && (old = h.find{|x| x[0] == tag})
89     old[1] = block
90     Plugins.def_sequel_method(self, old[2], 0, &block)
91   else
92     meth = Plugins.def_sequel_method(self, "validation_class_methods_#{hook}", 0, &block)
93     if hook.to_s =~ /^before/
94       h.unshift([tag, block, meth])
95     else
96       h << [tag, block, meth]
97     end
98   end
99 end