Class: Utopia::Controller::Rewrite::ExtractPrefixRule
- Defined in:
- lib/utopia/controller/rewrite.rb
Overview
A rule which extracts a prefix pattern from the request path.
Instance Method Summary collapse
-
#apply(context, request, path) ⇒ Object
Apply this prefix rule and execute its callback when it matches.
-
#freeze ⇒ Object
Freeze this object and its internal state.
-
#initialize(patterns, block) ⇒ ExtractPrefixRule
constructor
Initialize a typed prefix-extraction rule.
Methods inherited from Rule
Constructor Details
#initialize(patterns, block) ⇒ ExtractPrefixRule
Initialize a typed prefix-extraction rule.
43 44 45 46 |
# File 'lib/utopia/controller/rewrite.rb', line 43 def initialize(patterns, block) @matcher = Path::Matcher.new(patterns) @block = block end |
Instance Method Details
#apply(context, request, path) ⇒ Object
Apply this prefix rule and execute its callback when it matches.
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/utopia/controller/rewrite.rb', line 62 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 |
#freeze ⇒ Object
Freeze this object and its internal state.
50 51 52 53 54 55 |
# File 'lib/utopia/controller/rewrite.rb', line 50 def freeze @matcher.freeze @block.freeze super end |