public
Fork of rails/rails
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/methodmissing/rails.git
Avoid excessive AST traversal for Routing
methodmissing (author)
Thu Jul 10 05:18:29 -0700 2008
commit  19bb60109f728d1b972077a1a0291d1a27d34d34
tree    50802275c10ac7fbdbd3092a5d64c1d0cb77ce29
parent  5e8a69acdfe96ff1ba445244e9aa05ad4d2e615d
...
4
5
6
7
8
 
 
9
10
11
12
 
13
14
15
16
 
17
18
19
...
54
55
56
57
 
58
59
60
...
4
5
6
 
 
7
8
9
10
11
 
12
13
14
15
 
16
17
18
19
...
54
55
56
 
57
58
59
60
0
@@ -4,16 +4,16 @@ module ActionController
0
       attr_accessor :separators, :optional_separators
0
 
0
       def initialize
0
-        self.separators = Routing::SEPARATORS
0
-        self.optional_separators = %w( / )
0
+        @separators = Routing::SEPARATORS
0
+        @optional_separators = %w( / )
0
       end
0
 
0
       def separator_pattern(inverted = false)
0
-        "[#{'^' if inverted}#{Regexp.escape(separators.join)}]"
0
+        "[#{'^' if inverted}#{Regexp.escape(@separators.join)}]"
0
       end
0
 
0
       def interval_regexp
0
-        Regexp.new "(.*?)(#{separators.source}|$)"
0
+        Regexp.new "(.*?)(#{@separators.source}|$)"
0
       end
0
 
0
       def multiline_regexp?(expression)
0
@@ -54,7 +54,7 @@ module ActionController
0
           when /\A(#{separator_pattern(:inverted)}+)/ then StaticSegment.new($1)
0
           when Regexp.new(separator_pattern) then
0
             returning segment = DividerSegment.new($&) do
0
-              segment.is_optional = (optional_separators.include? $&)
0
+              segment.is_optional = (@optional_separators.include? $&)
0
             end
0
         end
0
         [segment, $~.post_match]
...
57
58
59
60
 
61
62
63
...
71
72
73
74
 
75
76
77
...
81
82
83
84
 
85
86
87
...
98
99
100
101
 
102
103
104
...
110
111
112
113
 
114
115
116
...
57
58
59
 
60
61
62
63
...
71
72
73
 
74
75
76
77
...
81
82
83
 
84
85
86
87
...
98
99
100
 
101
102
103
104
...
110
111
112
 
113
114
115
116
0
@@ -57,7 +57,7 @@ module ActionController
0
       # rather than triggering the expensive logic in +url_for+.
0
       class PositionalArguments < Optimiser
0
         def guard_condition
0
-          number_of_arguments = route.segment_keys.size
0
+          number_of_arguments = @route.segment_keys.size
0
           # if they're using foo_url(:id=>2) it's one 
0
           # argument, but we don't want to generate /foos/id2
0
           if number_of_arguments == 1
0
@@ -71,7 +71,7 @@ module ActionController
0
           elements = []
0
           idx = 0
0
 
0
-          if kind == :url
0
+          if @kind == :url
0
             elements << '#{request.protocol}'
0
             elements << '#{request.host_with_port}'
0
           end
0
@@ -81,7 +81,7 @@ module ActionController
0
           # The last entry in <tt>route.segments</tt> appears to *always* be a
0
           # 'divider segment' for '/' but we have assertions to ensure that
0
           # we don't include the trailing slashes, so skip them.
0
-          (route.segments.size == 1 ? route.segments : route.segments[0..-2]).each do |segment|
0
+          (@route.segments.size == 1 ? @route.segments : @route.segments[0..-2]).each do |segment|
0
             if segment.is_a?(DynamicSegment)
0
               elements << segment.interpolation_chunk("args[#{idx}].to_param")
0
               idx += 1
0
@@ -98,7 +98,7 @@ module ActionController
0
       # argument
0
       class PositionalArgumentsWithAdditionalParams < PositionalArguments
0
         def guard_condition
0
-          "(!defined?(default_url_options) || default_url_options.blank?) && defined?(request) && request && args.size == #{route.segment_keys.size + 1} && !args.last.has_key?(:anchor) && !args.last.has_key?(:port) && !args.last.has_key?(:host)"
0
+          "(!defined?(default_url_options) || default_url_options.blank?) && defined?(request) && request && args.size == #{@route.segment_keys.size + 1} && !args.last.has_key?(:anchor) && !args.last.has_key?(:port) && !args.last.has_key?(:host)"
0
         end
0
 
0
         # This case uses almost the same code as positional arguments, 
0
@@ -110,7 +110,7 @@ module ActionController
0
         # To avoid generating "http://localhost/?host=foo.example.com" we
0
         # can't use this optimisation on routes without any segments
0
         def applicable?
0
-          super && route.segment_keys.size > 0 
0
+          super && @route.segment_keys.size > 0 
0
         end
0
       end
0
 
...
17
18
19
20
 
21
22
23
...
52
53
54
55
 
56
57
58
...
60
61
62
63
 
64
65
66
...
72
73
74
75
 
76
77
78
...
92
93
94
95
 
96
97
98
99
100
101
102
 
103
104
105
...
108
109
110
111
 
112
113
114
...
176
177
178
179
 
180
181
182
...
187
188
189
190
191
 
 
192
193
194
...
197
198
199
200
 
201
202
203
204
 
205
206
207
...
221
222
223
224
225
 
 
226
227
228
229
230
231
232
 
 
233
234
235
...
17
18
19
 
20
21
22
23
...
52
53
54
 
55
56
57
58
...
60
61
62
 
63
64
65
66
...
72
73
74
 
75
76
77
78
...
92
93
94
 
95
96
97
98
99
100
101
 
102
103
104
105
...
108
109
110
 
111
112
113
114
...
176
177
178
 
179
180
181
182
...
187
188
189
 
 
190
191
192
193
194
...
197
198
199
 
200
201
202
203
 
204
205
206
207
...
221
222
223
 
 
224
225
226
227
228
229
230
 
 
231
232
233
234
235
0
@@ -17,7 +17,7 @@ module ActionController
0
       end
0
 
0
       def segment_keys
0
-        segments.collect do |segment|
0
+        @segments.collect do |segment|
0
           segment.key if segment.respond_to? :key
0
         end.compact
0
       end
0
@@ -52,7 +52,7 @@ module ActionController
0
       # Build several lines of code that extract values from the options hash. If any
0
       # of the values are missing or rejected then a return will be executed.
0
       def generation_extraction
0
-        segments.collect do |segment|
0
+        @segments.collect do |segment|
0
           segment.extraction_code
0
         end.compact * "\n"
0
       end
0
@@ -60,7 +60,7 @@ module ActionController
0
       # Produce a condition expression that will check the requirements of this route
0
       # upon generation.
0
       def generation_requirements
0
-        requirement_conditions = requirements.collect do |key, req|
0
+        requirement_conditions = @requirements.collect do |key, req|
0
           if req.is_a? Regexp
0
             value_regexp = Regexp.new "\\A#{req.to_s}\\Z"
0
             "hash[:#{key}] && #{value_regexp.inspect} =~ options[:#{key}]"
0
@@ -72,7 +72,7 @@ module ActionController
0
       end
0
 
0
       def generation_structure
0
-        segments.last.string_structure segments[0..-2]
0
+        @segments.last.string_structure @segments[0..-2]
0
       end
0
 
0
       # Write and compile a +recognize+ method for this Route.
0
@@ -92,14 +92,14 @@ module ActionController
0
       # recognition, not generation.
0
       def recognition_conditions
0
         result = ["(match = #{Regexp.new(recognition_pattern).inspect}.match(path))"]
0
-        result << "conditions[:method] === env[:method]" if conditions[:method]
0
+        result << "@conditions[:method] === env[:method]" if @conditions[:method]
0
         result
0
       end
0
 
0
       # Build the regular expression pattern that will match this route.
0
       def recognition_pattern(wrap = true)
0
         pattern = ''
0
-        segments.reverse_each do |segment|
0
+        @segments.reverse_each do |segment|
0
           pattern = segment.build_pattern pattern
0
         end
0
         wrap ? ("\\A" + pattern + "\\Z") : pattern
0
@@ -108,7 +108,7 @@ module ActionController
0
       # Write the code to extract the parameters from a matched route.
0
       def recognition_extraction
0
         next_capture = 1
0
-        extraction = segments.collect do |segment|
0
+        extraction = @segments.collect do |segment|
0
           x = segment.match_extraction(next_capture)
0
           next_capture += Regexp.new(segment.regexp_chunk).number_of_captures
0
           x
0
@@ -176,7 +176,7 @@ module ActionController
0
       #
0
       def parameter_shell
0
         @parameter_shell ||= returning({}) do |shell|
0
-          requirements.each do |key, requirement|
0
+          @requirements.each do |key, requirement|
0
             shell[key] = requirement unless requirement.is_a? Regexp
0
           end
0
         end
0
@@ -187,8 +187,8 @@ module ActionController
0
       # placed upon them.
0
       def significant_keys
0
         @significant_keys ||= returning [] do |sk|
0
-          segments.each { |segment| sk << segment.key if segment.respond_to? :key }
0
-          sk.concat requirements.keys
0
+          @segments.each { |segment| sk << segment.key if segment.respond_to? :key }
0
+          sk.concat @requirements.keys
0
           sk.uniq!
0
         end
0
       end
0
@@ -197,11 +197,11 @@ module ActionController
0
       # have defaults, or which are specified by non-regexp requirements.
0
       def defaults
0
         @defaults ||= returning({}) do |hash|
0
-          segments.each do |segment|
0
+          @segments.each do |segment|
0
             next unless segment.respond_to? :default
0
             hash[segment.key] = segment.default unless segment.default.nil?
0
           end
0
-          requirements.each do |key,req|
0
+          @requirements.each do |key,req|
0
             next if Regexp === req || req.nil?
0
             hash[key] = req
0
           end
0
@@ -221,15 +221,15 @@ module ActionController
0
 
0
       def to_s
0
         @to_s ||= begin
0
-          segs = segments.inject("") { |str,s| str << s.to_s }
0
-          "%-6s %-40s %s" % [(conditions[:method] || :any).to_s.upcase, segs, requirements.inspect]
0
+          segs = @segments.inject("") { |str,s| str << s.to_s }
0
+          "%-6s %-40s %s" % [(@conditions[:method] || :any).to_s.upcase, segs, @requirements.inspect]
0
         end
0
       end
0
 
0
     protected
0
       def requirement_for(key)
0
-        return requirements[key] if requirements.key? key
0
-        segments.each do |segment|
0
+        return @requirements[key] if @requirements.key? key
0
+        @segments.each do |segment|
0
           return segment.regexp if segment.respond_to?(:key) && segment.key == key
0
         end
0
         nil
...
79
80
81
82
 
83
84
85
86
87
 
88
89
90
...
92
93
94
95
 
96
97
98
99
100
 
101
102
103
104
 
105
106
107
108
 
109
110
111
...
144
145
146
147
 
148
149
150
...
185
186
187
188
 
189
190
191
192
193
194
195
196
 
 
197
198
199
...
209
210
211
212
213
 
 
214
215
216
...
220
221
222
223
 
224
225
226
227
 
228
229
230
...
238
239
240
241
242
 
 
243
244
245
...
249
250
251
252
253
254
 
 
 
255
256
257
...
259
260
261
262
 
263
264
265
266
267
268
269
 
270
271
272
...
308
309
310
311
 
312
313
314
...
351
352
353
354
 
355
356
357
...
410
411
412
413
 
414
415
416
 
417
418
419
420
 
421
422
423
...
79
80
81
 
82
83
84
85
86
 
87
88
89
90
...
92
93
94
 
95
96
97
98
99
 
100
101
102
103
 
104
105
106
107
 
108
109
110
111
...
144
145
146
 
147
148
149
150
...
185
186
187
 
188
189
190
191
192
193
194
 
 
195
196
197
198
199
...
209
210
211
 
 
212
213
214
215
216
...
220
221
222
 
223
224
225
226
 
227
228
229
230
...
238
239
240
 
 
241
242
243
244
245
...
249
250
251
 
 
 
252
253
254
255
256
257
...
259
260
261
 
262
263
264
265
266
267
268
 
269
270
271
272
...
308
309
310
 
311
312
313
314
...
351
352
353
 
354
355
356
357
...
410
411
412
 
413
414
415
 
416
417
418
419
 
420
421
422
423
0
@@ -79,12 +79,12 @@ module ActionController
0
         end
0
 
0
         def add(name, route)
0
-          routes[name.to_sym] = route
0
+          @routes[name.to_sym] = route
0
           define_named_route_methods(name, route)
0
         end
0
 
0
         def get(name)
0
-          routes[name.to_sym]
0
+          @routes[name.to_sym]
0
         end
0
 
0
         alias []=   add
0
@@ -92,20 +92,20 @@ module ActionController
0
         alias clear clear!
0
 
0
         def each
0
-          routes.each { |name, route| yield name, route }
0
+          @routes.each { |name, route| yield name, route }
0
           self
0
         end
0
 
0
         def names
0
-          routes.keys
0
+          @routes.keys
0
         end
0
 
0
         def length
0
-          routes.length
0
+          @routes.length
0
         end
0
 
0
         def reset!
0
-          old_routes = routes.dup
0
+          old_routes = @routes.dup
0
           clear!
0
           old_routes.each do |name, route|
0
             add(name, route)
0
@@ -144,7 +144,7 @@ module ActionController
0
               end
0
               protected :#{selector}
0
             end_eval
0
-            helpers << selector
0
+            @helpers << selector
0
           end
0
 
0
           def define_url_helper(route, name, kind, options)
0
@@ -185,15 +185,15 @@ module ActionController
0
               end
0
               protected :#{selector}
0
             end_eval
0
-            helpers << selector
0
+            @helpers << selector
0
           end
0
       end
0
 
0
       attr_accessor :routes, :named_routes, :configuration_file
0
 
0
       def initialize
0
-        self.routes = []
0
-        self.named_routes = NamedRouteCollection.new
0
+        @routes = []
0
+        @named_routes = NamedRouteCollection.new
0
       end
0
 
0
       # Subclasses and plugins may override this method to specify a different
0
@@ -209,8 +209,8 @@ module ActionController
0
       end
0
 
0
       def clear!
0
-        routes.clear
0
-        named_routes.clear
0
+        @routes.clear
0
+        @named_routes.clear
0
         @combined_regexp = nil
0
         @routes_by_controller = nil
0
         # This will force routing/recognition_optimization.rb
0
@@ -220,11 +220,11 @@ module ActionController
0
 
0
       def install_helpers(destinations = [ActionController::Base, ActionView::Base], regenerate_code = false)
0
         Array(destinations).each { |d| d.module_eval { include Helpers } }
0
-        named_routes.install(destinations, regenerate_code)
0
+        @named_routes.install(destinations, regenerate_code)
0
       end
0
 
0
       def empty?
0
-        routes.empty?
0
+        @routes.empty?
0
       end
0
 
0
       def load!
0
@@ -238,8 +238,8 @@ module ActionController
0
       alias reload! load!
0
 
0
       def reload
0
-        if @routes_last_modified && configuration_file
0
-          mtime = File.stat(configuration_file).mtime
0
+        if @routes_last_modified && @configuration_file
0
+          mtime = File.stat(@configuration_file).mtime
0
           # if it hasn't been changed, then just return
0
           return if mtime == @routes_last_modified
0
           # if it has changed then record the new time and fall to the load! below
0
@@ -249,9 +249,9 @@ module ActionController
0
       end
0
 
0
       def load_routes!
0
-        if configuration_file
0
-          load configuration_file
0
-          @routes_last_modified = File.stat(configuration_file).mtime
0
+        if @configuration_file
0
+          load @configuration_file
0
+          @routes_last_modified = File.stat(@configuration_file).mtime
0
         else
0
           add_route ":controller/:action/:id"
0
         end
0
@@ -259,14 +259,14 @@ module ActionController
0
 
0
       def add_route(path, options = {})
0
         route = builder.build(path, options)
0
-        routes << route
0
+        @routes << route
0
         route
0
       end
0
 
0
       def add_named_route(name, path, options = {})
0
         # TODO - is options EVER used?
0
         name = options[:name_prefix] + name.to_s if options[:name_prefix]
0
-        named_routes[name.to_sym] = add_route(path, options)
0
+        @named_routes[name.to_sym] = add_route(path, options)
0
       end
0
 
0
       def options_as_params(options)
0
@@ -308,7 +308,7 @@ module ActionController
0
         named_route_name = options.delete(:use_route)
0
         generate_all = options.delete(:generate_all)
0
         if named_route_name
0
-          named_route = named_routes[named_route_name]
0
+          named_route = @named_routes[named_route_name]
0
           options = named_route.parameter_shell.merge(options)
0
         end
0
 
0
@@ -351,7 +351,7 @@ module ActionController
0
 
0
           if generate_all
0
             # Used by caching to expire all paths for a resource
0
-            return routes.collect do |route|
0
+            return @routes.collect do |route|
0
               route.send!(method, options, merged, expire_on)
0
             end.compact
0
           end
0
@@ -410,14 +410,14 @@ module ActionController
0
       end
0
 
0
       def routes_for_controller_and_action(controller, action)
0
-        selected = routes.select do |route|
0
+        selected = @routes.select do |route|
0
           route.matches_controller_and_action? controller, action
0
         end
0
-        (selected.length == routes.length) ? routes : selected
0
+        (selected.length == @routes.length) ? @routes : selected
0
       end
0
 
0
       def routes_for_controller_and_action_and_keys(controller, action, keys)
0
-        selected = routes.select do |route|
0
+        selected = @routes.select do |route|
0
           route.matches_controller_and_action? controller, action
0
         end
0
         selected.sort_by do |route|
...
8
9
10
11
 
12
13
14
...
68
69
70
71
 
72
73
74
75
 
76
77
78
79
 
80
81
82
83
84
 
85
86
87
...
92
93
94
95
 
96
97
98
99
100
101
102
103
 
 
104
105
106
...
113
114
115
116
117
118
 
 
 
119
120
121
122
 
123
124
125
126
127
 
128
129
130
131
 
132
133
134
135
 
 
136
137
138
139
 
140
141
 
142
143
144
145
 
146
147
148
...
161
162
163
164
 
165
166
167
...
171
172
173
174
 
175
176
177
178
 
179
180
 
181
182
 
183
184
185
...
196
197
198
199
 
200
201
202
203
204
205
206
 
207
208
209
210
211
 
212
213
214
...
220
221
222
223
 
224
225
226
...
231
232
233
234
 
235
236
237
238
239
 
 
240
241
 
242
243
244
245
246
 
 
 
 
 
 
247
248
249
250
251
252
253
254
255
256
 
257
258
259
...
261
262
263
264
 
265
266
267
268
 
269
270
271
...
8
9
10
 
11
12
13
14
...
68
69
70
 
71
72
73
74
 
75
76
77
78
 
79
80
81
82
83
 
84
85
86
87
...
92
93
94
 
95
96
97
98
99
100
101
 
 
102
103
104
105
106
...
113
114
115
 
 
 
116
117
118
119
120
121
 
122
123
124
125
126
 
127
128
129
130
 
131
132
133
 
 
134
135
136
137
138
 
139
140
 
141
142
143
144
 
145
146
147
148
...
161
162
163
 
164
165
166
167
...
171
172
173
 
174
175
176
177
 
178
179
 
180
181
 
182
183
184
185
...
196
197
198
 
199
200
201
202
203
204
205
 
206
207
208
209
210
 
211
212
213
214
...
220
221
222
 
223
224
225
226
...
231
232
233
 
234
235
236
237
 
 
238
239
240
 
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
 
 
 
 
 
258
259
260
261
...
263
264
265
 
266
267
268
269
 
270
271
272
273
0
@@ -8,7 +8,7 @@ module ActionController
0
       alias_method :optional?, :is_optional
0
 
0
       def initialize
0
-        self.is_optional = false
0
+        @is_optional = false
0
       end
0
 
0
       def extraction_code
0
@@ -68,20 +68,20 @@ module ActionController
0
 
0
       def initialize(value = nil)
0
         super()
0
-        self.value = value
0
+        @value = value
0
       end
0
 
0
       def interpolation_chunk
0
-        raw? ? value : super
0
+        @raw ? @value : super
0
       end
0
 
0
       def regexp_chunk
0
-        chunk = Regexp.escape(value)
0
+        chunk = Regexp.escape(@value)
0
         optional? ? Regexp.optionalize(chunk) : chunk
0
       end
0
 
0
       def build_pattern(pattern)
0
-        escaped = Regexp.escape(value)
0
+        escaped = Regexp.escape(@value)
0
         if optional? && ! pattern.empty?
0
           "(?:#{Regexp.optionalize escaped}\\Z|#{escaped}#{Regexp.unoptionalize pattern})"
0
         elsif optional?
0
@@ -92,15 +92,15 @@ module ActionController
0
       end
0
 
0
       def to_s
0
-        value
0
+        @value
0
       end
0
     end
0
 
0
     class DividerSegment < StaticSegment #:nodoc:
0
       def initialize(value = nil)
0
         super(value)
0
-        self.raw = true
0
-        self.is_optional = true
0
+        @raw = true
0
+        @is_optional = true
0
       end
0
 
0
       def optionality_implied?
0
@@ -113,36 +113,36 @@ module ActionController
0
 
0
       def initialize(key = nil, options = {})
0
         super()
0
-        self.key = key
0
-        self.default = options[:default] if options.key? :default
0
-        self.is_optional = true if options[:optional] || options.key?(:default)
0
+        @key = key
0
+        @default = options[:default] if options.key? :default
0
+        @is_optional = true if options[:optional] || options.key?(:default)
0
       end
0
 
0
       def to_s
0
-        ":#{key}"
0
+        ":#{@key}"
0
       end
0
 
0
       # The local variable name that the value of this segment will be extracted to.
0
       def local_name
0
-        "#{key}_value"
0
+        "#{@key}_value"
0
       end
0
 
0
       def extract_value
0
-        "#{local_name} = hash[:#{key}] && hash[:#{key}].to_param #{"|| #{default.inspect}" if default}"
0
+        "#{local_name} = hash[:#{@key}] && hash[:#{@key}].to_param #{"|| #{@default.inspect}" if @default}"
0
       end
0
       def value_check
0
-        if default # Then we know it won't be nil
0
-          "#{value_regexp.inspect} =~ #{local_name}" if regexp
0
+        if @default # Then we know it won't be nil
0
+          "#{value_regexp.inspect} =~ #{local_name}" if @regexp
0
         elsif optional?
0
           # If we have a regexp check that the value is not given, or that it matches.
0
           # If we have no regexp, return nil since we do not require a condition.
0
-          "#{local_name}.nil? || #{value_regexp.inspect} =~ #{local_name}" if regexp
0
+          "#{local_name}.nil? || #{value_regexp.inspect} =~ #{local_name}" if @regexp
0
         else # Then it must be present, and if we have a regexp, it must match too.
0
-          "#{local_name} #{"&& #{value_regexp.inspect} =~ #{local_name}" if regexp}"
0
+          "#{local_name} #{"&& #{value_regexp.inspect} =~ #{local_name}" if @regexp}"
0
         end
0
       end
0
       def expiry_statement
0
-        "expired, hash = true, options if !expired && expire_on[:#{key}]"
0
+        "expired, hash = true, options if !expired && expire_on[:#{@key}]"
0
       end
0
 
0
       def extraction_code
0
@@ -161,7 +161,7 @@ module ActionController
0
           # If we should not appear in the url, just write the code for the prior
0
           # segments. This occurs if our value is the default value, or, if we are
0
           # optional, if we have nil as our value.
0
-          "if #{local_name} == #{default.inspect}\n" +
0
+          "if #{local_name} == #{@default.inspect}\n" +
0
             continue_string_structure(prior_segments) +
0
           "\nelse\n" + # Otherwise, write the code up to here
0
             "#{interpolation_statement(prior_segments)}\nend"
0
@@ -171,15 +171,15 @@ module ActionController
0
       end
0
 
0
       def value_regexp
0
-        Regexp.new "\\A#{regexp.to_s}\\Z" if regexp
0
+        Regexp.new "\\A#{@regexp.to_s}\\Z" if @regexp
0
       end
0
 
0
       def regexp_chunk
0
-        if regexp 
0
+        if @regexp 
0
           if regexp_has_modifiers?
0
-            "(#{regexp.to_s})"
0
+            "(#{@regexp.to_s})"
0
           else
0
-            "(#{regexp.source})"
0
+            "(#{@regexp.source})"
0
           end
0
         else
0
           "([^#{Routing::SEPARATORS.join}]+)"
0
@@ -196,19 +196,19 @@ module ActionController
0
       def match_extraction(next_capture)
0
         # All non code-related keys (such as :id, :slug) are URI-unescaped as
0
         # path parameters.
0
-        default_value = default ? default.inspect : nil
0
+        default_value = @default ? @default.inspect : nil
0
         %[
0
           value = if (m = match[#{next_capture}])
0
             URI.unescape(m)
0
           else
0
             #{default_value}
0
           end
0
-          params[:#{key}] = value if value
0
+          params[:#{@key}] = value if value
0
         ]
0
       end
0
 
0
       def optionality_implied?
0
-        [:action, :id].include? key
0
+        [:action, :id].include? @key
0
       end
0
 
0
       def regexp_has_modifiers?
0
@@ -220,7 +220,7 @@ module ActionController
0
     class ControllerSegment < DynamicSegment #:nodoc:
0
       def regexp_chunk
0
         possible_names = Routing.possible_controllers.collect { |name| Regexp.escape name }
0
-        "(?i-:(#{(regexp || Regexp.union(*possible_names)).source}))"
0
+        "(?i-:(#{(@regexp || Regexp.union(*possible_names)).source}))"
0
       end
0
 
0
       # Don't URI.escape the controller name since it may contain slashes.
0
@@ -231,29 +231,31 @@ module ActionController
0
       # Make sure controller names like Admin/Content are correctly normalized to
0
       # admin/content
0
       def extract_value
0
-        "#{local_name} = (hash[:#{key}] #{"|| #{default.inspect}" if default}).downcase"
0
+        "#{local_name} = (hash[:#{@key}] #{"|| #{@default.inspect}" if @default}).downcase"
0
       end
0
 
0
       def match_extraction(next_capture)
0
-        if default
0
-          "params[:#{key}] = match[#{next_capture}] ? match[#{next_capture}].downcase : '#{default}'"
0
+        if @default
0
+          "params[:#{@key}] = match[#{next_capture}] ? match[#{next_capture}].downcase : '#{@default}'"
0
         else
0
-          "params[:#{key}] = match[#{next_capture}].downcase if match[#{next_capture}]"
0
+          "params[:#{@key}] = match[#{next_capture}].downcase if match[#{next_capture}]"
0
         end
0
       end
0
     end
0
 
0
     class PathSegment < DynamicSegment #:nodoc:
0
+      
0
+      def initialize( *args )
0
+        super( *args )
0
+        @default = ''
0
+      end
0
+      
0
       def interpolation_chunk(value_code = "#{local_name}")
0
         "\#{#{value_code}}"
0
       end
0
 
0
       def extract_value
0
-        "#{local_name} = hash[:#{key}] && Array(hash[:#{key}]).collect { |path_component| URI.escape(path_component.to_param, ActionController::Routing::Segment::UNSAFE_PCHAR) }.to_param #{"|| #{default.inspect}" if default}"
0
-      end
0
-
0
-      def default
0
-        ''
0
+        "#{local_name} = hash[:#{@key}] && Array(hash[:#{@key}]).collect { |path_component| URI.escape(path_component.to_param, ActionController::Routing::Segment::UNSAFE_PCHAR) }.to_param #{"|| #{@default.inspect}" if @default}"
0
       end
0
 
0
       def default=(path)
0
@@ -261,11 +263,11 @@ module ActionController
0
       end
0
 
0
       def match_extraction(next_capture)
0
-        "params[:#{key}] = PathSegment::Result.new_escaped((match[#{next_capture}]#{" || " + default.inspect if default}).split('/'))#{" if match[" + next_capture + "]" if !default}"
0
+        "params[:#{@key}] = PathSegment::Result.new_escaped((match[#{next_capture}]#{" || " + @default.inspect if @default}).split('/'))#{" if match[" + next_capture + "]" if !@default}"
0
       end
0
 
0
       def regexp_chunk
0
-        regexp || "(.*)"
0
+        @regexp || "(.*)"
0
       end
0
 
0
       def optionality_implied?

Comments