Module: Roda::RodaPlugins::MatchHookArgs

Defined in:
lib/roda/plugins/match_hook_args.rb

Overview

The match_hook_args plugin adds hooks that are called upon a successful match by any of the matchers. It is similar to the match_hook plugin, but it allows for passing the matchers and block arguments for each match method.

plugin :match_hook_args

add_match_hook do |matchers, block_args|
  logger.debug("matchers: #{matchers.inspect}. #{block_args.inspect} yielded.")
end

# Term is an implicit matcher used for terminating matches, and
# will be included in the array of matchers yielded to the match hook 
# if a terminating match is used.
term = self.class::RodaRequest::TERM

route do |r|
  r.root do
    # for a request for /
    # matchers: nil, block_args: nil
  end

  r.on 'a', ['b', 'c'], Integer do |segment, id|
    # for a request for /a/b/1
    # matchers: ["a", ["b", "c"], Integer], block_args: ["b", 1]
  end

  r.get 'd' do
    # for a request for /d
    # matchers: ["d", term], block_args: []
  end
end

Defined Under Namespace

Modules: ClassMethods, InstanceMethods, RequestMethods

Class Method Summary collapse

Class Method Details

.configure(app) ⇒ Object



38
39
40
# File 'lib/roda/plugins/match_hook_args.rb', line 38

def self.configure(app)
  app.opts[:match_hook_args] ||= []
end