Class: Rack::Rewrite::RuleSet

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/rewrite/rule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ RuleSet

:nodoc:



7
8
9
10
# File 'lib/rack/rewrite/rule.rb', line 7

def initialize(options = {})#:nodoc:
  @rules = []
  @block_options = {}
end

Instance Attribute Details

#rulesObject (readonly)

Returns the value of attribute rules.



6
7
8
# File 'lib/rack/rewrite/rule.rb', line 6

def rules
  @rules
end

Instance Method Details

#r301(*args) ⇒ 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+.



33
34
35
# File 'lib/rack/rewrite/rule.rb', line 33

def r301(*args)
  add_rule :r301, *args
end

#r302(*args) ⇒ 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+.



46
47
48
# File 'lib/rack/rewrite/rule.rb', line 46

def r302(*args)
  add_rule :r302, *args
end

#r303(*args) ⇒ 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+.



58
59
60
# File 'lib/rack/rewrite/rule.rb', line 58

def r303(*args)
  add_rule :r303, *args
end

#r307(*args) ⇒ 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+.



70
71
72
# File 'lib/rack/rewrite/rule.rb', line 70

def r307(*args)
  add_rule :r307, *args
end

#rewrite(*args) ⇒ 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') }



23
24
25
# File 'lib/rack/rewrite/rule.rb', line 23

def rewrite(*args)
  add_rule :rewrite, *args
end

#send_data(*args) ⇒ 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') }



97
98
99
# File 'lib/rack/rewrite/rule.rb', line 97

def send_data(*args)
  add_rule :send_data, *args
end

#send_file(*args) ⇒ 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') }



81
82
83
# File 'lib/rack/rewrite/rule.rb', line 81

def send_file(*args)
  add_rule :send_file, *args
end

#with_options(options, &block) ⇒ Object (protected)



101
102
103
104
105
106
# File 'lib/rack/rewrite/rule.rb', line 101

def with_options(options, &block)
  old_options = @block_options
  @block_options = @block_options.merge(options)
  yield
  @block_options = old_options
end

#x_send_file(*args) ⇒ 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') }



90
91
92
# File 'lib/rack/rewrite/rule.rb', line 90

def x_send_file(*args)
  add_rule :x_send_file, *args
end