public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Pare down object creation during route building
jeremy (author)
Mon Nov 10 17:41:07 -0800 2008
commit  5db9f9b3ad47fadf0b3f12ada1c2ea7b9c15ded5
tree    62e09cf6ec6c70bd0319203862af82def8a5f094
parent  335a31524055c7dd79618ea79b3c18d827e25d3d
...
1
2
3
4
 
 
5
6
7
8
9
10
11
12
13
14
15
16
17
 
 
18
19
20
 
 
 
21
22
23
...
30
31
32
33
 
34
35
36
...
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
57
58
...
98
99
100
101
 
102
103
104
...
1
2
3
 
4
5
6
7
 
 
 
 
 
 
 
 
 
 
 
8
9
10
 
 
11
12
13
14
15
16
...
23
24
25
 
26
27
28
29
...
32
33
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
...
91
92
93
 
94
95
96
97
0
@@ -1,23 +1,16 @@
0
 module ActionController
0
   module Routing
0
     class RouteBuilder #:nodoc:
0
-      attr_accessor :separators, :optional_separators
0
+      attr_reader :separators, :optional_separators
0
+      attr_reader :separator_regexp, :nonseparator_regexp, :interval_regexp
0
 
0
       def initialize
0
-        self.separators = Routing::SEPARATORS
0
-        self.optional_separators = %w( / )
0
-      end
0
-
0
-      def separator_pattern(inverted = false)
0
-        "[#{'^' if inverted}#{Regexp.escape(separators.join)}]"
0
-      end
0
-
0
-      def interval_regexp
0
-        Regexp.new "(.*?)(#{separators.source}|$)"
0
-      end
0
+        @separators = Routing::SEPARATORS
0
+        @optional_separators = %w( / )
0
 
0
-      def multiline_regexp?(expression)
0
-        expression.options & Regexp::MULTILINE == Regexp::MULTILINE
0
+        @separator_regexp = /[#{Regexp.escape(separators.join)}]/
0
+        @nonseparator_regexp = /\A([^#{Regexp.escape(separators.join)}]+)/
0
+        @interval_regexp = /(.*?)(#{separator_regexp}|$)/
0
       end
0
 
0
       # Accepts a "route path" (a string defining a route), and returns the array
0
@@ -30,7 +23,7 @@ module ActionController
0
         rest, segments = path, []
0
 
0
         until rest.empty?
0
-          segment, rest = segment_for rest
0
+          segment, rest = segment_for(rest)
0
           segments << segment
0
         end
0
         segments
0
@@ -39,20 +32,20 @@ module ActionController
0
       # A factory method that returns a new segment instance appropriate for the
0
       # format of the given string.
0
       def segment_for(string)
0
-        segment = case string
0
-          when /\A:(\w+)/
0
-            key = $1.to_sym
0
-            case key
0
-              when :controller then ControllerSegment.new(key)
0
-              else DynamicSegment.new key
0
-            end
0
-          when /\A\*(\w+)/ then PathSegment.new($1.to_sym, :optional => true)
0
-          when /\A\?(.*?)\?/
0
-            StaticSegment.new($1, :optional => true)
0
-          when /\A(#{separator_pattern(:inverted)}+)/ then StaticSegment.new($1)
0
-          when Regexp.new(separator_pattern) then
0
-            DividerSegment.new($&, :optional => (optional_separators.include? $&))
0
-        end
0
+        segment =
0
+          case string
0
+            when /\A:(\w+)/
0
+              key = $1.to_sym
0
+              key == :controller ? ControllerSegment.new(key) : DynamicSegment.new(key)
0
+            when /\A\*(\w+)/
0
+              PathSegment.new($1.to_sym, :optional => true)
0
+            when /\A\?(.*?)\?/
0
+              StaticSegment.new($1, :optional => true)
0
+            when nonseparator_regexp
0
+              StaticSegment.new($1)
0
+            when separator_regexp
0
+              DividerSegment.new($&, :optional => optional_separators.include?($&))
0
+          end
0
         [segment, $~.post_match]
0
       end
0
 
0
@@ -98,7 +91,7 @@ module ActionController
0
             if requirement.source =~ %r{\A(\\A|\^)|(\\Z|\\z|\$)\Z}
0
               raise ArgumentError, "Regexp anchor characters are not allowed in routing requirements: #{requirement.inspect}"
0
             end
0
-            if multiline_regexp?(requirement)
0
+            if requirement.multiline?
0
               raise ArgumentError, "Regexp multiline option not allowed in routing requirements: #{requirement.inspect}"
0
             end
0
             segment.regexp = requirement
...
27
28
29
 
 
 
 
30
31
32
...
27
28
29
30
31
32
33
34
35
36
0
@@ -27,6 +27,10 @@ class Regexp #:nodoc:
0
     Regexp.new("|#{source}").match('').captures.length
0
   end
0
 
0
+  def multiline?
0
+    options & MULTILINE == MULTILINE
0
+  end
0
+
0
   class << self
0
     def optionalize(pattern)
0
       case unoptionalize(pattern)

Comments