Skip to content
This repository
Browse code

update AD::Journey to follow Rails coding conventions

  • Loading branch information...
commit eb493f5ac84f2d65fbd1666e1496f0a8deafa27f 1 parent 42b555d
Francesco Rodríguez authored December 20, 2012
2  actionpack/Rakefile
@@ -80,4 +80,4 @@ rule '.rb' => '.y' do |t|
80 80
   sh "racc -l -o #{t.name} #{t.source}"
81 81
 end
82 82
 
83  
-task :compile => 'lib/action_dispatch/journey/parser.rb'
  83
+task compile: 'lib/action_dispatch/journey/parser.rb'
166  actionpack/lib/action_dispatch/journey/formatter.rb
@@ -5,17 +5,17 @@ module Journey
5 5
     class Formatter # :nodoc:
6 6
       attr_reader :routes
7 7
 
8  
-      def initialize routes
  8
+      def initialize(routes)
9 9
         @routes = routes
10 10
         @cache  = nil
11 11
       end
12 12
 
13  
-      def generate type, name, options, recall = {}, parameterize = nil
14  
-        constraints = recall.merge options
  13
+      def generate(type, name, options, recall = {}, parameterize = nil)
  14
+        constraints = recall.merge(options)
15 15
         missing_keys = []
16 16
 
17 17
         match_route(name, constraints) do |route|
18  
-          parameterized_parts = extract_parameterized_parts route, options, recall, parameterize
  18
+          parameterized_parts = extract_parameterized_parts(route, options, recall, parameterize)
19 19
           next if !name && route.requirements.empty? && route.parts.empty?
20 20
 
21 21
           missing_keys = missing_keys(route, parameterized_parts)
@@ -35,112 +35,110 @@ def clear
35 35
       end
36 36
 
37 37
       private
38  
-      def extract_parameterized_parts route, options, recall, parameterize = nil
39  
-        constraints = recall.merge options
40  
-        data = constraints.dup
41 38
 
42  
-        keys_to_keep = route.parts.reverse.drop_while { |part|
43  
-          !options.key?(part) || (options[part] || recall[part]).nil?
44  
-        } | route.required_parts
  39
+        def extract_parameterized_parts(route, options, recall, parameterize = nil)
  40
+          constraints = recall.merge(options)
  41
+          data = constraints.dup
45 42
 
46  
-        (data.keys - keys_to_keep).each do |bad_key|
47  
-          data.delete bad_key
48  
-        end
  43
+          keys_to_keep = route.parts.reverse.drop_while { |part|
  44
+            !options.key?(part) || (options[part] || recall[part]).nil?
  45
+          } | route.required_parts
  46
+
  47
+          (data.keys - keys_to_keep).each do |bad_key|
  48
+            data.delete(bad_key)
  49
+          end
49 50
 
50  
-        parameterized_parts = data.dup
  51
+          parameterized_parts = data.dup
51 52
 
52  
-        if parameterize
53  
-          parameterized_parts.each do |k,v|
54  
-            parameterized_parts[k] = parameterize.call(k, v)
  53
+          if parameterize
  54
+            parameterized_parts.each do |k, v|
  55
+              parameterized_parts[k] = parameterize.call(k, v)
  56
+            end
55 57
           end
56  
-        end
57 58
 
58  
-        parameterized_parts.keep_if { |_,v| v  }
59  
-        parameterized_parts
60  
-      end
  59
+          parameterized_parts.keep_if { |_, v| v  }
  60
+          parameterized_parts
  61
+        end
61 62
 
62  
-      def named_routes
63  
-        routes.named_routes
64  
-      end
  63
+        def named_routes
  64
+          routes.named_routes
  65
+        end
65 66
 
66  
-      def match_route name, options
67  
-        if named_routes.key? name
68  
-          yield named_routes[name]
69  
-        else
70  
-          #routes = possibles(@cache, options.to_a)
71  
-          routes = non_recursive(cache, options.to_a)
  67
+        def match_route(name, options)
  68
+          if named_routes.key?(name)
  69
+            yield named_routes[name]
  70
+          else
  71
+            routes = non_recursive(cache, options.to_a)
72 72
 
73  
-          hash = routes.group_by { |_, r|
74  
-            r.score options
75  
-          }
  73
+            hash = routes.group_by { |_, r| r.score(options) }
76 74
 
77  
-          hash.keys.sort.reverse_each do |score|
78  
-            next if score < 0
  75
+            hash.keys.sort.reverse_each do |score|
  76
+              next if score < 0
79 77
 
80  
-            hash[score].sort_by { |i,_| i }.each do |_,route|
81  
-              yield route
  78
+              hash[score].sort_by { |i, _| i }.each do |_, route|
  79
+                yield route
  80
+              end
82 81
             end
83 82
           end
84 83
         end
85  
-      end
86 84
 
87  
-      def non_recursive cache, options
88  
-        routes = []
89  
-        stack  = [cache]
  85
+        def non_recursive(cache, options)
  86
+          routes = []
  87
+          stack  = [cache]
90 88
 
91  
-        while stack.any?
92  
-          c = stack.shift
93  
-          routes.concat c[:___routes] if c.key? :___routes
  89
+          while stack.any?
  90
+            c = stack.shift
  91
+            routes.concat(c[:___routes]) if c.key?(:___routes)
94 92
 
95  
-          options.each do |pair|
96  
-            stack << c[pair] if c.key? pair
  93
+            options.each do |pair|
  94
+              stack << c[pair] if c.key?(pair)
  95
+            end
97 96
           end
98  
-        end
99 97
 
100  
-        routes
101  
-      end
  98
+          routes
  99
+        end
102 100
 
103  
-      # Returns an array populated with missing keys if any are present.
104  
-      def missing_keys route, parts
105  
-        missing_keys = []
106  
-        tests = route.path.requirements
107  
-        route.required_parts.each { |key|
108  
-          if tests.key? key
109  
-            missing_keys << key unless /\A#{tests[key]}\Z/ === parts[key]
110  
-          else
111  
-            missing_keys << key unless parts[key]
112  
-          end
113  
-        }
114  
-        missing_keys
115  
-      end
  101
+        # Returns an array populated with missing keys if any are present.
  102
+        def missing_keys(route, parts)
  103
+          missing_keys = []
  104
+          tests = route.path.requirements
  105
+          route.required_parts.each { |key|
  106
+            if tests.key?(key)
  107
+              missing_keys << key unless /\A#{tests[key]}\Z/ === parts[key]
  108
+            else
  109
+              missing_keys << key unless parts[key]
  110
+            end
  111
+          }
  112
+          missing_keys
  113
+        end
116 114
 
117  
-      def possibles cache, options, depth = 0
118  
-        cache.fetch(:___routes) { [] } + options.find_all { |pair|
119  
-          cache.key? pair
120  
-        }.map { |pair|
121  
-          possibles(cache[pair], options, depth + 1)
122  
-        }.flatten(1)
123  
-      end
  115
+        def possibles(cache, options, depth = 0)
  116
+          cache.fetch(:___routes) { [] } + options.find_all { |pair|
  117
+            cache.key?(pair)
  118
+          }.map { |pair|
  119
+            possibles(cache[pair], options, depth + 1)
  120
+          }.flatten(1)
  121
+        end
124 122
 
125  
-      # Returns +true+ if no missing keys are present, otherwise +false+.
126  
-      def verify_required_parts! route, parts
127  
-        missing_keys(route, parts).empty?
128  
-      end
  123
+        # Returns +true+ if no missing keys are present, otherwise +false+.
  124
+        def verify_required_parts!(route, parts)
  125
+          missing_keys(route, parts).empty?
  126
+        end
129 127
 
130  
-      def build_cache
131  
-        root = { :___routes => [] }
132  
-        routes.each_with_index do |route, i|
133  
-          leaf = route.required_defaults.inject(root) do |h, tuple|
134  
-            h[tuple] ||= {}
  128
+        def build_cache
  129
+          root = { ___routes: [] }
  130
+          routes.each_with_index do |route, i|
  131
+            leaf = route.required_defaults.inject(root) do |h, tuple|
  132
+              h[tuple] ||= {}
  133
+            end
  134
+            (leaf[:___routes] ||= []) << [i, route]
135 135
           end
136  
-          (leaf[:___routes] ||= []) << [i, route]
  136
+          root
137 137
         end
138  
-        root
139  
-      end
140 138
 
141  
-      def cache
142  
-        @cache ||= build_cache
143  
-      end
  139
+        def cache
  140
+          @cache ||= build_cache
  141
+        end
144 142
     end
145 143
   end
146 144
 end
81  actionpack/lib/action_dispatch/journey/gtg/builder.rb
@@ -8,10 +8,10 @@ class Builder # :nodoc:
8 8
 
9 9
         attr_reader :root, :ast, :endpoints
10 10
 
11  
-        def initialize root
12  
-          @root         = root
13  
-          @ast          = Nodes::Cat.new root, DUMMY
14  
-          @followpos    = nil
  11
+        def initialize(root)
  12
+          @root      = root
  13
+          @ast       = Nodes::Cat.new root, DUMMY
  14
+          @followpos = nil
15 15
         end
16 16
 
17 17
         def transition_table
@@ -35,21 +35,21 @@ def transition_table
35 35
                 to   = state_id[Object.new]
36 36
                 dtrans[from, to] = sym
37 37
 
38  
-                dtrans.add_accepting to
39  
-                ps.each { |state| dtrans.add_memo to, state.memo }
  38
+                dtrans.add_accepting(to)
  39
+                ps.each { |state| dtrans.add_memo(to, state.memo) }
40 40
               else
41 41
                 dtrans[state_id[s], state_id[u]] = sym
42 42
 
43  
-                if u.include? DUMMY
  43
+                if u.include?(DUMMY)
44 44
                   to = state_id[u]
45 45
 
46  
-                  accepting = ps.find_all { |l| followpos(l).include? DUMMY }
  46
+                  accepting = ps.find_all { |l| followpos(l).include?(DUMMY) }
47 47
 
48 48
                   accepting.each { |accepting_state|
49  
-                    dtrans.add_memo to, accepting_state.memo
  49
+                    dtrans.add_memo(to, accepting_state.memo)
50 50
                   }
51 51
 
52  
-                  dtrans.add_accepting state_id[u]
  52
+                  dtrans.add_accepting(state_id[u])
53 53
                 end
54 54
               end
55 55
 
@@ -60,7 +60,7 @@ def transition_table
60 60
           dtrans
61 61
         end
62 62
 
63  
-        def nullable? node
  63
+        def nullable?(node)
64 64
           case node
65 65
           when Nodes::Group
66 66
             true
@@ -73,18 +73,18 @@ def nullable? node
73 73
           when Nodes::Terminal
74 74
             !node.left
75 75
           when Nodes::Unary
76  
-            nullable? node.left
  76
+            nullable?(node.left)
77 77
           else
78 78
             raise ArgumentError, 'unknown nullable: %s' % node.class.name
79 79
           end
80 80
         end
81 81
 
82  
-        def firstpos node
  82
+        def firstpos(node)
83 83
           case node
84 84
           when Nodes::Star
85 85
             firstpos(node.left)
86 86
           when Nodes::Cat
87  
-            if nullable? node.left
  87
+            if nullable?(node.left)
88 88
               firstpos(node.left) | firstpos(node.right)
89 89
             else
90 90
               firstpos(node.left)
@@ -100,14 +100,14 @@ def firstpos node
100 100
           end
101 101
         end
102 102
 
103  
-        def lastpos node
  103
+        def lastpos(node)
104 104
           case node
105 105
           when Nodes::Star
106 106
             firstpos(node.left)
107 107
           when Nodes::Or
108 108
             node.children.map { |c| lastpos(c) }.flatten.uniq
109 109
           when Nodes::Cat
110  
-            if nullable? node.right
  110
+            if nullable?(node.right)
111 111
               lastpos(node.left) | lastpos(node.right)
112 112
             else
113 113
               lastpos(node.right)
@@ -121,40 +121,41 @@ def lastpos node
121 121
           end
122 122
         end
123 123
 
124  
-        def followpos node
  124
+        def followpos(node)
125 125
           followpos_table[node]
126 126
         end
127 127
 
128 128
         private
129  
-        def followpos_table
130  
-          @followpos ||= build_followpos
131  
-        end
132 129
 
133  
-        def build_followpos
134  
-          table = Hash.new { |h,k| h[k] = [] }
135  
-          @ast.each do |n|
136  
-            case n
137  
-            when Nodes::Cat
138  
-              lastpos(n.left).each do |i|
139  
-                table[i] += firstpos(n.right)
140  
-              end
141  
-            when Nodes::Star
142  
-              lastpos(n).each do |i|
143  
-                table[i] += firstpos(n)
  130
+          def followpos_table
  131
+            @followpos ||= build_followpos
  132
+          end
  133
+
  134
+          def build_followpos
  135
+            table = Hash.new { |h, k| h[k] = [] }
  136
+            @ast.each do |n|
  137
+              case n
  138
+              when Nodes::Cat
  139
+                lastpos(n.left).each do |i|
  140
+                  table[i] += firstpos(n.right)
  141
+                end
  142
+              when Nodes::Star
  143
+                lastpos(n).each do |i|
  144
+                  table[i] += firstpos(n)
  145
+                end
144 146
               end
145 147
             end
  148
+            table
146 149
           end
147  
-          table
148  
-        end
149 150
 
150  
-        def symbol edge
151  
-          case edge
152  
-          when Journey::Nodes::Symbol
153  
-            edge.regexp
154  
-          else
155  
-            edge.left
  151
+          def symbol(edge)
  152
+            case edge
  153
+            when Journey::Nodes::Symbol
  154
+              edge.regexp
  155
+            else
  156
+              edge.left
  157
+            end
156 158
           end
157  
-        end
158 159
       end
159 160
     end
160 161
   end
12  actionpack/lib/action_dispatch/journey/gtg/simulator.rb
@@ -6,7 +6,7 @@ module GTG # :nodoc:
6 6
       class MatchData # :nodoc:
7 7
         attr_reader :memos
8 8
 
9  
-        def initialize memos
  9
+        def initialize(memos)
10 10
           @memos = memos
11 11
         end
12 12
       end
@@ -14,12 +14,12 @@ def initialize memos
14 14
       class Simulator # :nodoc:
15 15
         attr_reader :tt
16 16
 
17  
-        def initialize transition_table
  17
+        def initialize(transition_table)
18 18
           @tt = transition_table
19 19
         end
20 20
 
21  
-        def simulate string
22  
-          input = StringScanner.new string
  21
+        def simulate(string)
  22
+          input = StringScanner.new(string)
23 23
           state = [0]
24 24
           while sym = input.scan(%r([/.?]|[^/.?]+))
25 25
             state = tt.move(state, sym)
@@ -31,9 +31,9 @@ def simulate string
31 31
 
32 32
           return if acceptance_states.empty?
33 33
 
34  
-          memos = acceptance_states.map { |x| tt.memo x }.flatten.compact
  34
+          memos = acceptance_states.map { |x| tt.memo(x) }.flatten.compact
35 35
 
36  
-          MatchData.new memos
  36
+          MatchData.new(memos)
37 37
         end
38 38
 
39 39
         alias :=~    :simulate
49  actionpack/lib/action_dispatch/journey/gtg/transition_table.rb
@@ -15,7 +15,7 @@ def initialize
15 15
           @memos         = Hash.new { |h,k| h[k] = [] }
16 16
         end
17 17
 
18  
-        def add_accepting state
  18
+        def add_accepting(state)
19 19
           @accepting[state] = true
20 20
         end
21 21
 
@@ -23,24 +23,24 @@ def accepting_states
23 23
           @accepting.keys
24 24
         end
25 25
 
26  
-        def accepting? state
  26
+        def accepting?(state)
27 27
           @accepting[state]
28 28
         end
29 29
 
30  
-        def add_memo idx, memo
  30
+        def add_memo(idx, memo)
31 31
           @memos[idx] << memo
32 32
         end
33 33
 
34  
-        def memo idx
  34
+        def memo(idx)
35 35
           @memos[idx]
36 36
         end
37 37
 
38  
-        def eclosure t
  38
+        def eclosure(t)
39 39
           Array(t)
40 40
         end
41 41
 
42  
-        def move t, a
43  
-          move_string(t, a).concat move_regexp(t, a)
  42
+        def move(t, a)
  43
+          move_string(t, a).concat(move_regexp(t, a))
44 44
         end
45 45
 
46 46
         def to_json
@@ -55,15 +55,15 @@ def to_json
55 55
           end
56 56
 
57 57
           JSON.dump({
58  
-            :regexp_states => simple_regexp,
59  
-            :string_states => @string_states,
60  
-            :accepting     => @accepting
  58
+            regexp_states: simple_regexp,
  59
+            string_states: @string_states,
  60
+            accepting:     @accepting
61 61
           })
62 62
         end
63 63
 
64 64
         def to_svg
65  
-          svg = IO.popen("dot -Tsvg", 'w+') { |f|
66  
-            f.write to_dot
  65
+          svg = IO.popen('dot -Tsvg', 'w+') { |f|
  66
+            f.write(to_dot)
67 67
             f.close_write
68 68
             f.readlines
69 69
           }
@@ -71,7 +71,7 @@ def to_svg
71 71
           svg.join.sub(/width="[^"]*"/, '').sub(/height="[^"]*"/, '')
72 72
         end
73 73
 
74  
-        def visualizer paths, title = 'FSM'
  74
+        def visualizer(paths, title = 'FSM')
75 75
           viz_dir   = File.join File.dirname(__FILE__), '..', 'visualizer'
76 76
           fsm_js    = File.read File.join(viz_dir, 'fsm.js')
77 77
           fsm_css   = File.read File.join(viz_dir, 'fsm.css')
@@ -110,7 +110,7 @@ def visualizer paths, title = 'FSM'
110 110
           template.result(binding)
111 111
         end
112 112
 
113  
-        def []= from, to, sym
  113
+        def []=(from, to, sym)
114 114
           case sym
115 115
           when String
116 116
             @string_states[from][sym] = to
@@ -136,19 +136,20 @@ def transitions
136 136
         end
137 137
 
138 138
         private
139  
-        def move_regexp t, a
140  
-          return [] if t.empty?
141 139
 
142  
-          t.map { |s|
143  
-            @regexp_states[s].map { |re,v| re === a ? v : nil }
144  
-          }.flatten.compact.uniq
145  
-        end
  140
+          def move_regexp(t, a)
  141
+            return [] if t.empty?
146 142
 
147  
-        def move_string t, a
148  
-          return [] if t.empty?
  143
+            t.map { |s|
  144
+              @regexp_states[s].map { |re, v| re === a ? v : nil }
  145
+            }.flatten.compact.uniq
  146
+          end
149 147
 
150  
-          t.map { |s| @string_states[s][a] }.compact
151  
-        end
  148
+          def move_string(t, a)
  149
+            return [] if t.empty?
  150
+
  151
+            t.map { |s| @string_states[s][a] }.compact
  152
+          end
152 153
       end
153 154
     end
154 155
   end
34  actionpack/lib/action_dispatch/journey/nfa/builder.rb
@@ -5,23 +5,23 @@ module ActionDispatch
5 5
   module Journey # :nodoc:
6 6
     module NFA # :nodoc:
7 7
       class Visitor < Visitors::Visitor # :nodoc:
8  
-        def initialize tt
  8
+        def initialize(tt)
9 9
           @tt = tt
10 10
           @i  = -1
11 11
         end
12 12
 
13  
-        def visit_CAT node
14  
-          left  = visit node.left
15  
-          right = visit node.right
  13
+        def visit_CAT(node)
  14
+          left  = visit(node.left)
  15
+          right = visit(node.right)
16 16
 
17  
-          @tt.merge left.last, right.first
  17
+          @tt.merge(left.last, right.first)
18 18
 
19 19
           [left.first, right.last]
20 20
         end
21 21
 
22  
-        def visit_GROUP node
  22
+        def visit_GROUP(node)
23 23
           from  = @i += 1
24  
-          left  = visit node.left
  24
+          left  = visit(node.left)
25 25
           to    = @i += 1
26 26
 
27 27
           @tt.accepting = to
@@ -33,14 +33,14 @@ def visit_GROUP node
33 33
           [from, to]
34 34
         end
35 35
 
36  
-        def visit_OR node
37  
-          from  = @i += 1
38  
-          children = node.children.map { |c| visit c }
39  
-          to    = @i += 1
  36
+        def visit_OR(node)
  37
+          from = @i += 1
  38
+          children = node.children.map { |c| visit(c) }
  39
+          to   = @i += 1
40 40
 
41 41
           children.each do |child|
42  
-            @tt[from, child.first]  = nil
43  
-            @tt[child.last, to]     = nil
  42
+            @tt[from, child.first] = nil
  43
+            @tt[child.last, to]    = nil
44 44
           end
45 45
 
46 46
           @tt.accepting = to
@@ -48,26 +48,26 @@ def visit_OR node
48 48
           [from, to]
49 49
         end
50 50
 
51  
-        def terminal node
  51
+        def terminal(node)
52 52
           from_i = @i += 1 # new state
53 53
           to_i   = @i += 1 # new state
54 54
 
55 55
           @tt[from_i, to_i] = node
56 56
           @tt.accepting = to_i
57  
-          @tt.add_memo to_i, node.memo
  57
+          @tt.add_memo(to_i, node.memo)
58 58
 
59 59
           [from_i, to_i]
60 60
         end
61 61
       end
62 62
 
63 63
       class Builder # :nodoc:
64  
-        def initialize ast
  64
+        def initialize(ast)
65 65
           @ast = ast
66 66
         end
67 67
 
68 68
         def transition_table
69 69
           tt = TransitionTable.new
70  
-          Visitor.new(tt).accept @ast
  70
+          Visitor.new(tt).accept(@ast)
71 71
           tt
72 72
         end
73 73
       end
18  actionpack/lib/action_dispatch/journey/nfa/simulator.rb
@@ -6,7 +6,7 @@ module NFA # :nodoc:
6 6
       class MatchData # :nodoc:
7 7
         attr_reader :memos
8 8
 
9  
-        def initialize memos
  9
+        def initialize(memos)
10 10
           @memos = memos
11 11
         end
12 12
       end
@@ -14,29 +14,29 @@ def initialize memos
14 14
       class Simulator # :nodoc:
15 15
         attr_reader :tt
16 16
 
17  
-        def initialize transition_table
  17
+        def initialize(transition_table)
18 18
           @tt = transition_table
19 19
         end
20 20
 
21  
-        def simulate string
22  
-          input = StringScanner.new string
23  
-          state = tt.eclosure 0
  21
+        def simulate(string)
  22
+          input = StringScanner.new(string)
  23
+          state = tt.eclosure(0)
24 24
           until input.eos?
25 25
             sym   = input.scan(%r([/.?]|[^/.?]+))
26 26
 
27 27
             # FIXME: tt.eclosure is not needed for the GTG
28  
-            state = tt.eclosure tt.move(state, sym)
  28
+            state = tt.eclosure(tt.move(state, sym))
29 29
           end
30 30
 
31 31
           acceptance_states = state.find_all { |s|
32  
-            tt.accepting? tt.eclosure(s).sort.last
  32
+            tt.accepting?(tt.eclosure(s).sort.last)
33 33
           }
34 34
 
35 35
           return if acceptance_states.empty?
36 36
 
37  
-          memos = acceptance_states.map { |x| tt.memo x }.flatten.compact
  37
+          memos = acceptance_states.map { |x| tt.memo(x) }.flatten.compact
38 38
 
39  
-          MatchData.new memos
  39
+          MatchData.new(memos)
40 40
         end
41 41
 
42 42
         alias :=~    :simulate
61  actionpack/lib/action_dispatch/journey/nfa/transition_table.rb
@@ -16,7 +16,7 @@ def initialize
16 16
           @inverted  = nil
17 17
         end
18 18
 
19  
-        def accepting? state
  19
+        def accepting?(state)
20 20
           accepting == state
21 21
         end
22 22
 
@@ -24,20 +24,20 @@ def accepting_states
24 24
           [accepting]
25 25
         end
26 26
 
27  
-        def add_memo idx, memo
  27
+        def add_memo(idx, memo)
28 28
           @memos[idx] = memo
29 29
         end
30 30
 
31  
-        def memo idx
  31
+        def memo(idx)
32 32
           @memos[idx]
33 33
         end
34 34
 
35  
-        def []= i, f, s
  35
+        def []=(i, f, s)
36 36
           @table[f][i] = s
37 37
         end
38 38
 
39  
-        def merge left, right
40  
-          @memos[right] = @memos.delete left
  39
+        def merge(left, right)
  40
+          @memos[right] = @memos.delete(left)
41 41
           @table[right] = @table.delete(left)
42 42
         end
43 43
 
@@ -45,11 +45,10 @@ def states
45 45
           (@table.keys + @table.values.map(&:keys).flatten).uniq
46 46
         end
47 47
 
48  
-        ###
49  
-        # Returns a generalized transition graph with reduced states.  The states
  48
+        # Returns a generalized transition graph with reduced states. The states
50 49
         # are reduced like a DFA, but the table must be simulated like an NFA.
51 50
         #
52  
-        # Edges of the GTG are regular expressions
  51
+        # Edges of the GTG are regular expressions.
53 52
         def generalized_table
54 53
           gt       = GTG::TransitionTable.new
55 54
           marked   = {}
@@ -80,28 +79,26 @@ def generalized_table
80 79
           final_groups.each do |states|
81 80
             id = state_id[states]
82 81
 
83  
-            gt.add_accepting id
  82
+            gt.add_accepting(id)
84 83
             save = states.find { |s|
85 84
               @memos.key?(s) && eclosure(s).sort.last == accepting
86 85
             }
87 86
 
88  
-            gt.add_memo id, memo(save)
  87
+            gt.add_memo(id, memo(save))
89 88
           end
90 89
 
91 90
           gt
92 91
         end
93 92
 
94  
-        ###
95 93
         # Returns set of NFA states to which there is a transition on ast symbol
96 94
         # +a+ from some state +s+ in +t+.
97  
-        def following_states t, a
  95
+        def following_states(t, a)
98 96
           Array(t).map { |s| inverted[s][a] }.flatten.uniq
99 97
         end
100 98
 
101  
-        ###
102 99
         # Returns set of NFA states to which there is a transition on ast symbol
103 100
         # +a+ from some state +s+ in +t+.
104  
-        def move t, a
  101
+        def move(t, a)
105 102
           Array(t).map { |s|
106 103
             inverted[s].keys.compact.find_all { |sym|
107 104
               sym === a
@@ -113,10 +110,9 @@ def alphabet
113 110
           inverted.values.map(&:keys).flatten.compact.uniq.sort_by { |x| x.to_s }
114 111
         end
115 112
 
116  
-        ###
117 113
         # Returns a set of NFA states reachable from some NFA state +s+ in set
118 114
         # +t+ on nil-transitions alone.
119  
-        def eclosure t
  115
+        def eclosure(t)
120 116
           stack = Array(t)
121 117
           seen  = {}
122 118
           children = []
@@ -128,7 +124,7 @@ def eclosure t
128 124
             seen[s] = true
129 125
             children << s
130 126
 
131  
-            stack.concat inverted[s][nil]
  127
+            stack.concat(inverted[s][nil])
132 128
           end
133 129
 
134 130
           children.uniq
@@ -141,26 +137,27 @@ def transitions
141 137
         end
142 138
 
143 139
         private
144  
-        def inverted
145  
-          return @inverted if @inverted
146 140
 
147  
-          @inverted = Hash.new { |h,from|
148  
-            h[from] = Hash.new { |j,s| j[s] = [] }
149  
-          }
  141
+          def inverted
  142
+            return @inverted if @inverted
  143
+
  144
+            @inverted = Hash.new { |h, from|
  145
+              h[from] = Hash.new { |j, s| j[s] = [] }
  146
+            }
150 147
 
151  
-          @table.each { |to, hash|
152  
-            hash.each { |from, sym|
153  
-              if sym
154  
-                sym = Nodes::Symbol === sym ? sym.regexp : sym.left
155  
-              end
  148
+            @table.each { |to, hash|
  149
+              hash.each { |from, sym|
  150
+                if sym
  151
+                  sym = Nodes::Symbol === sym ? sym.regexp : sym.left
  152
+                end
156 153
 
157  
-              @inverted[from][sym] << to
  154
+                @inverted[from][sym] << to
  155
+              }
158 156
             }
159  
-          }
160 157
 
161  
-          @inverted
  158
+            @inverted
  159
+          end
162 160
         end
163  
-      end
164 161
     end
165 162
   end
166 163
 end
10  actionpack/lib/action_dispatch/journey/nodes/node.rb
@@ -8,7 +8,7 @@ class Node # :nodoc:
8 8
 
9 9
         attr_accessor :left, :memo
10 10
 
11  
-        def initialize left
  11
+        def initialize(left)
12 12
           @left = left
13 13
           @memo = nil
14 14
         end
@@ -51,7 +51,7 @@ def type; :LITERAL; end
51 51
       end
52 52
 
53 53
       class Dummy < Literal # :nodoc:
54  
-        def initialize x = Object.new
  54
+        def initialize(x = Object.new)
55 55
           super
56 56
         end
57 57
 
@@ -71,7 +71,7 @@ class Symbol < Terminal # :nodoc:
71 71
         alias :symbol :regexp
72 72
 
73 73
         DEFAULT_EXP = /[^\.\/\?]+/
74  
-        def initialize left
  74
+        def initialize(left)
75 75
           super
76 76
           @regexp = DEFAULT_EXP
77 77
         end
@@ -98,7 +98,7 @@ def type; :STAR; end
98 98
       class Binary < Node # :nodoc:
99 99
         attr_accessor :right
100 100
 
101  
-        def initialize left, right
  101
+        def initialize(left, right)
102 102
           super(left)
103 103
           @right = right
104 104
         end
@@ -113,7 +113,7 @@ def type; :CAT; end
113 113
       class Or < Node # :nodoc:
114 114
         attr_reader :children
115 115
 
116  
-        def initialize children
  116
+        def initialize(children)
117 117
           @children = children
118 118
         end
119 119
 
4  actionpack/lib/action_dispatch/journey/parser_extras.rb
@@ -10,8 +10,8 @@ def initialize
10 10
         @scanner = Scanner.new
11 11
       end
12 12
 
13  
-      def parse string
14  
-        @scanner.scan_setup string
  13
+      def parse(string)
  14
+        @scanner.scan_setup(string)
15 15
         do_parse
16 16
       end
17 17
 
61  actionpack/lib/action_dispatch/journey/path/pattern.rb
@@ -4,18 +4,18 @@ module Path # :nodoc:
4 4
       class Pattern # :nodoc:
5 5
         attr_reader :spec, :requirements, :anchored
6 6
 
7  
-        def initialize strexp
  7
+        def initialize(strexp)
8 8
           parser = Journey::Parser.new
9 9
 
10 10
           @anchored = true
11 11
 
12 12
           case strexp
13 13
           when String
14  
-            @spec         = parser.parse strexp
  14
+            @spec         = parser.parse(strexp)
15 15
             @requirements = {}
16 16
             @separators   = "/.?"
17 17
           when Router::Strexp
18  
-            @spec         = parser.parse strexp.path
  18
+            @spec         = parser.parse(strexp.path)
19 19
             @requirements = strexp.requirements
20 20
             @separators   = strexp.separators.join
21 21
             @anchored     = strexp.anchor
@@ -61,20 +61,20 @@ def optional_names
61 61
         class RegexpOffsets < Journey::Visitors::Visitor # :nodoc:
62 62
           attr_reader :offsets
63 63
 
64  
-          def initialize matchers
  64
+          def initialize(matchers)
65 65
             @matchers      = matchers
66 66
             @capture_count = [0]
67 67
           end
68 68
 
69  
-          def visit node
  69
+          def visit(node)
70 70
             super
71 71
             @capture_count
72 72
           end
73 73
 
74  
-          def visit_SYMBOL node
  74
+          def visit_SYMBOL(node)
75 75
             node = node.to_sym
76 76
 
77  
-            if @matchers.key? node
  77
+            if @matchers.key?(node)
78 78
               re = /#{@matchers[node]}|/
79 79
               @capture_count.push((re.match('').length - 1) + (@capture_count.last || 0))
80 80
             else
@@ -84,51 +84,51 @@ def visit_SYMBOL node
84 84
         end
85 85
 
86 86
         class AnchoredRegexp < Journey::Visitors::Visitor # :nodoc:
87  
-          def initialize separator, matchers
  87
+          def initialize(separator, matchers)
88 88
             @separator = separator
89 89
             @matchers  = matchers
90 90
             @separator_re = "([^#{separator}]+)"
91 91
             super()
92 92
           end
93 93
 
94  
-          def accept node
  94
+          def accept(node)
95 95
             %r{\A#{visit node}\Z}
96 96
           end
97 97
 
98  
-          def visit_CAT node
  98
+          def visit_CAT(node)
99 99
             [visit(node.left), visit(node.right)].join
100 100
           end
101 101
 
102  
-          def visit_SYMBOL node
  102
+          def visit_SYMBOL(node)
103 103
             node = node.to_sym
104 104
 
105  
-            return @separator_re unless @matchers.key? node
  105
+            return @separator_re unless @matchers.key?(node)
106 106
 
107 107
             re = @matchers[node]
108 108
             "(#{re})"
109 109
           end
110 110
 
111  
-          def visit_GROUP node
  111
+          def visit_GROUP(node)
112 112
             "(?:#{visit node.left})?"
113 113
           end
114 114
 
115  
-          def visit_LITERAL node
116  
-            Regexp.escape node.left
  115
+          def visit_LITERAL(node)
  116
+            Regexp.escape(node.left)
117 117
           end
118 118
           alias :visit_DOT :visit_LITERAL
119 119
 
120  
-          def visit_SLASH node
  120
+          def visit_SLASH(node)
121 121
             node.left
122 122
           end
123 123
 
124  
-          def visit_STAR node
  124
+          def visit_STAR(node)
125 125
             re = @matchers[node.left.to_sym] || '.+'
126 126
             "(#{re})"
127 127
           end
128 128
         end
129 129
 
130 130
         class UnanchoredRegexp < AnchoredRegexp # :nodoc:
131  
-          def accept node
  131
+          def accept(node)
132 132
             %r{\A#{visit node}}
133 133
           end
134 134
         end
@@ -136,7 +136,7 @@ def accept node
136 136
         class MatchData # :nodoc:
137 137
           attr_reader :names
138 138
 
139  
-          def initialize names, offsets, match
  139
+          def initialize(names, offsets, match)
140 140
             @names   = names
141 141
             @offsets = offsets
142 142
             @match   = match
@@ -146,7 +146,7 @@ def captures
146 146
             (length - 1).times.map { |i| self[i + 1] }
147 147
           end
148 148
 
149  
-          def [] x
  149
+          def [](x)
150 150
             idx = @offsets[x - 1] + x
151 151
             @match[idx]
152 152
           end
@@ -164,9 +164,9 @@ def to_s
164 164
           end
165 165
         end
166 166
 
167  
-        def match other
  167
+        def match(other)
168 168
           return unless match = to_regexp.match(other)
169  
-          MatchData.new names, offsets, match
  169
+          MatchData.new(names, offsets, match)
170 170
         end
171 171
         alias :=~ :match
172 172
 
@@ -179,16 +179,17 @@ def to_regexp
179 179
         end
180 180
 
181 181
         private
182  
-        def regexp_visitor
183  
-          @anchored ? AnchoredRegexp : UnanchoredRegexp
184  
-        end
185 182
 
186  
-        def offsets
187  
-          return @offsets if @offsets
  183
+          def regexp_visitor
  184
+            @anchored ? AnchoredRegexp : UnanchoredRegexp
  185
+          end
188 186
 
189  
-          viz = RegexpOffsets.new @requirements
190  
-          @offsets = viz.accept spec
191  
-        end
  187
+          def offsets
  188
+            return @offsets if @offsets
  189
+
  190
+            viz = RegexpOffsets.new(@requirements)
  191
+            @offsets = viz.accept(spec)
  192
+          end
192 193
       end
193 194
     end
194 195
   end
8  actionpack/lib/action_dispatch/journey/route.rb
@@ -11,7 +11,7 @@ class Route # :nodoc:
11 11
       ##
12 12
       # +path+ is a path constraint.
13 13
       # +constraints+ is a hash of constraints to be applied to this route.
14  
-      def initialize name, app, path, constraints, defaults = {}
  14
+      def initialize(name, app, path, constraints, defaults = {})
15 15
         constraints  = constraints.dup
16 16
         @name        = name
17 17
         @app         = app
@@ -52,7 +52,7 @@ def required_keys
52 52
         path.required_names.map { |x| x.to_sym } + required_defaults.keys
53 53
       end