Class: Apache::RewriteCondition

Inherits:
MatchableThing show all
Includes:
RegularExpressionMatcher
Defined in:
lib/apache/rewrites.rb

Overview

A RewriteCond

Instance Attribute Summary

Attributes inherited from MatchableThing

#from, #to

Instance Method Summary collapse

Methods included from RegularExpressionMatcher

#match?

Methods inherited from MatchableThing

#forbidden?, #from_tester, #require_regexp?, #stop_if_match?, #to_a

Constructor Details

#initializeRewriteCondition

Create a new RewriteCond



366
367
368
369
# File 'lib/apache/rewrites.rb', line 366

def initialize
  super
  @options = nil
end

Instance Method Details

#actual_toObject



380
381
382
383
384
# File 'lib/apache/rewrites.rb', line 380

def actual_to
  to = @to
  to = to[1..-1] if inverse_result?
  to
end

#inverse_result?Boolean

Returns:

  • (Boolean)


376
377
378
# File 'lib/apache/rewrites.rb', line 376

def inverse_result?
  @to[0..0] == '!'
end

#rule(from, to, *opts) ⇒ Object Also known as: cond

Define a RewriteCond

rule "%{REQUEST_FILENAME}", "^/here", :case_insensitive #=>
  RewriteCond "%{REQUEST_FILENAME}" "^/here" [NC]

Additional parameters can include the following:

  • :or #=> [OR]

  • :case_insensitive #=> [NC]

  • :no_vary #=> [NV]



357
358
359
360
361
# File 'lib/apache/rewrites.rb', line 357

def rule(from, to, *opts)
  super(from, to)

  @options = opts.rewrite_cond_optionify.rewrite_option_listify
end

#tagObject



346
# File 'lib/apache/rewrites.rb', line 346

def tag; 'RewriteCond'; end

#test(from, opts = {}) ⇒ Object

Test this RewriteCond



387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# File 'lib/apache/rewrites.rb', line 387

def test(from, opts = {})
  super(from, opts)
  source = @from.replace_placeholderize(opts)

  to = actual_to

  case to
    when '-f'
      result = opts[:files].include?(source) if opts[:files]
    else
      result = source[Regexp.new(to)]
  end

  inverse_result? ? !result : result
end

#to_sObject

Convert this tag to a String.



372
373
374
# File 'lib/apache/rewrites.rb', line 372

def to_s
  "#{tag} #{[@from.quoteize, @to.quoteize, @options].compact.flatten * " "}"
end