module Roda::RodaPlugins::Hooks::ClassMethods

Public Instance Methods

after(&block) click to toggle source

Add an after hook. If there is already an after hook defined, use a proc that instance_execs the existing after proc and then instance_execs the given after proc, so that the given after proc always executes after the previous one.

# File lib/roda/plugins/hooks.rb, line 44
def after(&block)
  if block
    @after = if b = @after
      @after = proc do |res|
        instance_exec(res, &b)
        instance_exec(res, &block)
      end
    else
      block
    end
  end
  @after
end
before(&block) click to toggle source

Add a before hook. If there is already a before hook defined, use a proc that instance_execs the give before proc and then instance_execs the existing before proc, so that the given before proc always executes before the previous one.

# File lib/roda/plugins/hooks.rb, line 62
def before(&block)
  if block
    @before = if b = @before
      @before = proc do
        instance_exec(&block)
        instance_exec(&b)
      end
    else
      block
    end
  end
  @before
end
inherited(subclass) click to toggle source

Copy the before and after hooks into the subclasses when inheriting

Calls superclass method
# File lib/roda/plugins/hooks.rb, line 78
def inherited(subclass)
  super
  subclass.instance_variable_set(:@before, @before)
  subclass.instance_variable_set(:@after, @after)
end