Class: Apache::RewriteRule
- Inherits:
-
MatchableThing
- Object
- MatchableThing
- Apache::RewriteRule
- Includes:
- RegularExpressionMatcher
- Defined in:
- lib/apache/rewrites.rb
Overview
A RewriteRule definition
Instance Attribute Summary
Attributes inherited from MatchableThing
Instance Method Summary collapse
-
#cond(from, to, *opts) ⇒ Object
Add a RewriteCondition to this RewriteRule.
- #ensure_opts!(opts) ⇒ Object
- #forbidden? ⇒ Boolean
- #initial_blank! ⇒ Object
-
#initialize ⇒ RewriteRule
constructor
A new instance of RewriteRule.
- #match?(from, opts = {}) ⇒ Boolean
- #require_regexp? ⇒ Boolean
-
#rule(from, to, options = {}) ⇒ Object
Define the rule, passing in additional options.
- #stop_if_match? ⇒ Boolean
- #tag ⇒ Object
-
#test(from, opts = {}) ⇒ Object
Test this RewriteRule, ensuring the RewriteConds also match.
- #to_a ⇒ Object
- #to_s ⇒ Object
Methods inherited from MatchableThing
Constructor Details
#initialize ⇒ RewriteRule
Returns a new instance of RewriteRule.
231 232 233 234 235 236 |
# File 'lib/apache/rewrites.rb', line 231 def initialize super @conditions = [] @options = nil @input_options = {} end |
Instance Method Details
#cond(from, to, *opts) ⇒ Object
Add a RewriteCondition to this RewriteRule
261 262 263 264 265 266 |
# File 'lib/apache/rewrites.rb', line 261 def cond(from, to, *opts) rewrite_cond = RewriteCondition.new rewrite_cond.cond(from, to, *opts) @conditions << rewrite_cond end |
#ensure_opts!(opts) ⇒ Object
291 292 293 294 |
# File 'lib/apache/rewrites.rb', line 291 def ensure_opts!(opts) raise "Options must be a hash" if !opts raise "Options must be a hash" if !opts.kind_of? ::Hash end |
#forbidden? ⇒ Boolean
311 312 313 |
# File 'lib/apache/rewrites.rb', line 311 def forbidden? @input_options[:forbidden] end |
#initial_blank! ⇒ Object
268 269 270 |
# File 'lib/apache/rewrites.rb', line 268 def initial_blank! @conditions.empty? ? nil : '' end |
#match?(from, opts = {}) ⇒ Boolean
296 297 298 299 300 301 302 303 304 305 |
# File 'lib/apache/rewrites.rb', line 296 def match?(from, opts = {}) ensure_opts!(opts) opts[:request_uri] = from @conditions.each do |cond| return false if !cond.test(from, opts) end super(from, opts) end |
#require_regexp? ⇒ Boolean
315 |
# File 'lib/apache/rewrites.rb', line 315 def require_regexp?; true; end |
#rule(from, to, options = {}) ⇒ Object
Define the rule, passing in additional options
rule %r^/here, ‘/there’, { :last => true, :preserve_query_string => true }
Options for the options hash are:
-
:last => true #=> [L]
-
:forbidden => true #=> [F]
-
:no_escape => true #=> [NE]
-
:redirect => true #=> [R]
-
:redirect => 302 #=> [R=302]
-
:pass_through => true #=> [PT]
-
:preserve_query_string => true #=> [QSA]
-
:query_string_append => true #=> [QSA]
-
:env => ‘what’ #=> [E=what]
252 253 254 255 256 257 258 |
# File 'lib/apache/rewrites.rb', line 252 def rule(from, to, = {}) super(from, to) @input_options = @options = .rewrite_rule_optionify.rewrite_option_listify end |
#stop_if_match? ⇒ Boolean
307 308 309 |
# File 'lib/apache/rewrites.rb', line 307 def stop_if_match? @input_options[:last] end |
#tag ⇒ Object
229 |
# File 'lib/apache/rewrites.rb', line 229 def tag; 'RewriteRule'; end |
#test(from, opts = {}) ⇒ Object
Test this RewriteRule, ensuring the RewriteConds also match
281 282 283 284 285 286 287 288 289 |
# File 'lib/apache/rewrites.rb', line 281 def test(from, opts = {}) ensure_opts!(opts) opts[:request_uri] = from result = from result = super(from, opts) if match?(from, opts) result.replace_placeholderize(opts) end |
#to_a ⇒ Object
276 277 278 |
# File 'lib/apache/rewrites.rb', line 276 def to_a [ initial_blank!, @conditions.collect(&:to_s), super ].flatten end |
#to_s ⇒ Object
272 273 274 |
# File 'lib/apache/rewrites.rb', line 272 def to_s "#{tag} #{[@from.source.quoteize, @to.quoteize, @options].compact.flatten * " "}" end |