class ExtractPrefixRule
A rule which extracts a prefix pattern from the request path.
Definitions
def initialize(patterns, block)
Initialize a typed prefix-extraction rule.
Signature
-
parameter
patternsHash The path rewrite patterns.
-
parameter
blockProc The block.
Implementation
def initialize(patterns, block)
@matcher = Path::Matcher.new(patterns)
@block = block
end
def freeze
Freeze this object and its internal state.
Signature
-
returns
self This object.
Implementation
def freeze
@matcher.freeze
@block.freeze
super
end
def apply(context, request, path)
Apply this prefix rule and execute its callback when it matches.
Signature
-
parameter
contextObject The context.
-
parameter
requestRack::Request The request.
-
parameter
pathUtopia::Path | String The path.
-
returns
Path The unmatched suffix, or the original path when the rule does not match.
Implementation
def apply(context, request, path)
if match_data = @matcher.match(path)
apply_match_to_context(match_data, context)
if @block
context.instance_exec(request, path, match_data, &@block)
end
return match_data.post_match
else
return path
end
end