Class: Rack::Rewrite::RuleSet
- Inherits:
-
Object
- Object
- Rack::Rewrite::RuleSet
- Defined in:
- lib/rack/rewrite/rule.rb
Overview
Internal collection that holds the ordered list of rewrite/redirect
rules a given Rack::Rewrite instance evaluates against an
incoming request.
Instance Attribute Summary collapse
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Instance Method Summary collapse
-
#initialize(_options = {}) ⇒ RuleSet
constructor
:nodoc:.
-
#r301 ⇒ Object
(also: #moved_permanently, #p)
protected
Creates a redirect rule that will send a 301 when matching.
-
#r302 ⇒ Object
(also: #found)
protected
Creates a redirect rule that will send a 302 when matching.
-
#r303 ⇒ Object
(also: #see_other)
protected
Creates a redirect rule that will send a 303 when matching.
-
#r307 ⇒ Object
(also: #temporary_redirect, #t)
protected
Creates a redirect rule that will send a 307 when matching.
-
#rewrite ⇒ Object
protected
Creates a rewrite rule that will simply rewrite the REQUEST_URI, PATH_INFO, and QUERY_STRING headers of the Rack environment.
-
#send_data ⇒ Object
protected
Creates a rule taht will render the raw data if matched send_data /*/, 'public/system/maintenance.html', :if => Proc.new { File.exist?('public/system/maintenance.html') }.
-
#send_file ⇒ Object
protected
Creates a rule that will render a file if matched.
- #with_options(options) ⇒ Object protected
-
#x_send_file ⇒ Object
protected
Creates a rule that will render a file using x-send-file if matched.
Constructor Details
#initialize(_options = {}) ⇒ RuleSet
:nodoc:
12 13 14 15 |
# File 'lib/rack/rewrite/rule.rb', line 12 def initialize( = {}) # :nodoc: @rules = [] @block_options = {} end |
Instance Attribute Details
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
10 11 12 |
# File 'lib/rack/rewrite/rule.rb', line 10 def rules @rules end |
Instance Method Details
#r301 ⇒ Object (protected) Also known as: moved_permanently, p
Creates a redirect rule that will send a 301 when matching.
r301 '/wiki/John_Trupiano', '/john'
r301 '/contact-us.php', '/contact-us'
You can use +moved_permanently+ or just +p+ instead of +r301+.
39 40 41 |
# File 'lib/rack/rewrite/rule.rb', line 39 def r301(*) add_rule(:r301, *) end |
#r302 ⇒ Object (protected) Also known as: found
Creates a redirect rule that will send a 302 when matching.
r302 '/wiki/John_Trupiano', '/john'
r302 '/wiki/(.*)', 'http://www.google.com/?q=$1'
You can use +found+ instead of +r302+.
52 53 54 |
# File 'lib/rack/rewrite/rule.rb', line 52 def r302(*) add_rule(:r302, *) end |
#r303 ⇒ Object (protected) Also known as: see_other
Creates a redirect rule that will send a 303 when matching.
r303 '/wiki/John_Trupiano', '/john'
r303 '/wiki/(.*)', 'http://www.google.com/?q=$1'
You can use +see_other+ instead of +r303+.
64 65 66 |
# File 'lib/rack/rewrite/rule.rb', line 64 def r303(*) add_rule(:r303, *) end |
#r307 ⇒ Object (protected) Also known as: temporary_redirect, t
Creates a redirect rule that will send a 307 when matching.
r307 '/wiki/John_Trupiano', '/john'
r307 '/wiki/(.*)', 'http://www.google.com/?q=$1'
You can use +temporary_redirect+ or +t+ instead of +r307+.
76 77 78 |
# File 'lib/rack/rewrite/rule.rb', line 76 def r307(*) add_rule(:r307, *) end |
#rewrite ⇒ Object (protected)
Creates a rewrite rule that will simply rewrite the REQUEST_URI,
PATH_INFO, and QUERY_STRING headers of the Rack environment. The
user's browser will continue to show the initially requested URL.
rewrite '/wiki/John_Trupiano', '/john'
rewrite %r/wiki/(\w+)_\w+, '/$1'
rewrite %rRack::Rewrite::RuleSet.((.*), '/maintenance.html', :if => lambda { File.exist?('maintenance.html') }
29 30 31 |
# File 'lib/rack/rewrite/rule.rb', line 29 def rewrite(*) add_rule(:rewrite, *) end |
#send_data ⇒ Object (protected)
Creates a rule taht will render the raw data if matched
send_data /*/, 'public/system/maintenance.html',
:if => Proc.new { File.exist?('public/system/maintenance.html') }
103 104 105 |
# File 'lib/rack/rewrite/rule.rb', line 103 def send_data(*) add_rule(:send_data, *) end |
#send_file ⇒ Object (protected)
Creates a rule that will render a file if matched.
send_file /*/, 'public/system/maintenance.html',
:if => Proc.new { File.exist?('public/system/maintenance.html') }
87 88 89 |
# File 'lib/rack/rewrite/rule.rb', line 87 def send_file(*) add_rule(:send_file, *) end |
#with_options(options) ⇒ Object (protected)
107 108 109 110 111 112 |
# File 'lib/rack/rewrite/rule.rb', line 107 def (, &) = @block_options @block_options = @block_options.merge() yield @block_options = end |
#x_send_file ⇒ Object (protected)
Creates a rule that will render a file using x-send-file
if matched.
x_send_file /*/, 'public/system/maintenance.html',
:if => Proc.new { File.exist?('public/system/maintenance.html') }
96 97 98 |
# File 'lib/rack/rewrite/rule.rb', line 96 def x_send_file(*) add_rule(:x_send_file, *) end |