@@ -18,6 +18,7 @@ class Redirect
1818 def initialize ( env , host , options = { } , &block )
1919 self . env = env
2020 self . host = host
21+ self . block = block
2122 self . ignore = Array ( options [ :ignore ] )
2223 self . conditions = Array ( options [ :if ] )
2324 self . cache_control = options [ :cache_control ]
@@ -37,6 +38,7 @@ def response
3738
3839 attr_accessor :env
3940 attr_accessor :host
41+ attr_accessor :block
4042 attr_accessor :ignore
4143 attr_accessor :conditions
4244 attr_accessor :cache_control
@@ -55,6 +57,17 @@ def any_match?(patterns, request_uri)
5557 }
5658 end
5759
60+ def enabled?
61+ return true if conditions . empty?
62+
63+ any_match? ( conditions , request_uri )
64+ end
65+
66+ def evaluated_host
67+ return @evaluated_host if defined? ( @evaluated_host )
68+ @evaluated_host = block && block . call ( env ) || host
69+ end
70+
5871 def headers
5972 {
6073 'cache-control' => cache_control ,
@@ -63,12 +76,6 @@ def headers
6376 } . reject { |_ , value | !value }
6477 end
6578
66- def enabled?
67- return true if conditions . empty?
68-
69- any_match? ( conditions , request_uri )
70- end
71-
7279 def ignored?
7380 return false if ignore . empty?
7481
@@ -85,10 +92,6 @@ def new_url
8592 uri . normalize . to_s
8693 end
8794
88- def evaluated_host
89- @evaluated_host ||= block and block . call ( env ) or host
90- end
91-
9295 def request_uri
9396 @request_uri ||= Addressable ::URI . parse ( Rack ::Request . new ( env ) . url )
9497 end
0 commit comments