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 50
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 56
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 61
def hook_blocks(hook)
  # SEQUEL6: Remove
  Sequel::Deprecation.deprecate("The hook_blocks class method in the hook_class_methods plugin is deprecated and will be removed in Sequel 6.")
  @hooks[hook].each{|_,v,_| yield v}
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, line 68
def hook_methods_for(hook)
  @hooks[hook].each{|_,_,m| yield m}
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 79
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
    Plugins.def_sequel_method(self, old[2], 0, &block)
  else
    meth = Plugins.def_sequel_method(self, "validation_class_methods_#{hook}", 0, &block)
    if hook.to_s =~ /^before/
      h.unshift([tag, block, meth])
    else
      h << [tag, block, meth]
    end
  end
end