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
- #freeze ⇒ Object
-
#initialize(patterns, block) ⇒ ExtractPrefixRule
constructor
A new instance of ExtractPrefixRule.
Methods inherited from Rule
Constructor Details
#initialize(patterns, block) ⇒ ExtractPrefixRule
Returns a new instance of ExtractPrefixRule.
33 34 35 36 |
# File 'lib/utopia/controller/rewrite.rb', line 33 def initialize(patterns, block) @matcher = Path::Matcher.new(patterns) @block = block end |
Instance Method Details
#apply(context, request, path) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/utopia/controller/rewrite.rb', line 45 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
38 39 40 41 42 43 |
# File 'lib/utopia/controller/rewrite.rb', line 38 def freeze @matcher.freeze @block.freeze super end |