Class: Utopia::Controller::Rewrite::Rewriter
- Inherits:
-
Object
- Object
- Utopia::Controller::Rewrite::Rewriter
- Defined in:
- lib/utopia/controller/rewrite.rb
Overview
Rewrite a request path based on a set of defined rules.
Instance Attribute Summary collapse
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Instance Method Summary collapse
-
#apply(context, request, path) ⇒ Object
-
#call(context, request, path) ⇒ Object
-
#extract_prefix(**patterns, &block) ⇒ Object
-
#initialize ⇒ Rewriter
constructor
A new instance of Rewriter.
Constructor Details
#initialize ⇒ Rewriter
Returns a new instance of Rewriter
77 78 79 |
# File 'lib/utopia/controller/rewrite.rb', line 77 def initialize @rules = [] end |
Instance Attribute Details
#rules ⇒ Object (readonly)
Returns the value of attribute rules
81 82 83 |
# File 'lib/utopia/controller/rewrite.rb', line 81 def rules @rules end |
Instance Method Details
#apply(context, request, path) ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/utopia/controller/rewrite.rb', line 87 def apply(context, request, path) @rules.each do |rule| path = rule.apply(context, request, path) end return path end |
#call(context, request, path) ⇒ Object
95 96 97 |
# File 'lib/utopia/controller/rewrite.rb', line 95 def call(context, request, path) path.components = apply(context, request, path).components end |
#extract_prefix(**patterns, &block) ⇒ Object
83 84 85 |
# File 'lib/utopia/controller/rewrite.rb', line 83 def extract_prefix(**patterns, &block) @rules << ExtractPrefixRule.new(patterns, block) end |