Module: Roda::RodaPlugins::MatchAffix
- Defined in:
- lib/roda/plugins/match_affix.rb
Overview
The match_affix plugin allows changing the default prefix and suffix used for match patterns. Roda’s default behavior for a match pattern like "albums"
is to use the pattern /\A\/(?:albums)(?=\/|\z)/
. This prefixes the pattern with /
and suffixes it with (?=\/|\z)
. With the match_affix plugin, you can change the prefix and suffix to use. So if you want to be explicit and require a leading /
in patterns, you can set the prefix to ""
. If you want to consume a trailing slash instead of leaving it, you can set the suffix to (\/|\z)
.
You set the prefix and suffix to use by passing arguments when loading the plugin:
plugin :match_affix, ""
will load the plugin and use an empty prefix.
plugin :match_affix, "", /(\/|\z)/
will use an empty prefix and change the suffix to consume a trailing slash.
plugin :match_affix, nil, /(\/|\z)/
will not modify the prefix and will change the suffix to consume a trailing slash.
Defined Under Namespace
Modules: RequestClassMethods, RequestMethods
Constant Summary collapse
- PREFIX =
"/".freeze
- SUFFIX =
"(?=\/|\z)".freeze
Class Method Summary collapse
-
.configure(app, prefix, suffix = nil) ⇒ Object
Set the default prefix and suffix to use in match patterns, if a non-nil value is given.
Class Method Details
.configure(app, prefix, suffix = nil) ⇒ Object
Set the default prefix and suffix to use in match patterns, if a non-nil value is given.
33 34 35 36 |
# File 'lib/roda/plugins/match_affix.rb', line 33 def self.configure(app, prefix, suffix=nil) app.opts[:match_prefix] = prefix if prefix app.opts[:match_suffix] = suffix if suffix end |