actionpack 4.2.11.1 → 6.0.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionpack might be problematic. Click here for more details.

Files changed (182) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +212 -526
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +9 -9
  5. data/lib/abstract_controller/asset_paths.rb +2 -0
  6. data/lib/abstract_controller/base.rb +47 -50
  7. data/lib/{action_controller → abstract_controller}/caching/fragments.rb +64 -17
  8. data/lib/abstract_controller/caching.rb +66 -0
  9. data/lib/abstract_controller/callbacks.rb +59 -31
  10. data/lib/abstract_controller/collector.rb +9 -13
  11. data/lib/abstract_controller/error.rb +6 -0
  12. data/lib/abstract_controller/helpers.rb +31 -30
  13. data/lib/abstract_controller/logger.rb +2 -0
  14. data/lib/abstract_controller/railties/routes_helpers.rb +5 -3
  15. data/lib/abstract_controller/rendering.rb +42 -41
  16. data/lib/abstract_controller/translation.rb +12 -9
  17. data/lib/abstract_controller/url_for.rb +2 -0
  18. data/lib/abstract_controller.rb +12 -5
  19. data/lib/action_controller/api/api_rendering.rb +16 -0
  20. data/lib/action_controller/api.rb +150 -0
  21. data/lib/action_controller/base.rb +25 -22
  22. data/lib/action_controller/caching.rb +13 -57
  23. data/lib/action_controller/form_builder.rb +50 -0
  24. data/lib/action_controller/log_subscriber.rb +15 -17
  25. data/lib/action_controller/metal/basic_implicit_render.rb +13 -0
  26. data/lib/action_controller/metal/conditional_get.rb +124 -44
  27. data/lib/action_controller/metal/content_security_policy.rb +51 -0
  28. data/lib/action_controller/metal/cookies.rb +3 -3
  29. data/lib/action_controller/metal/data_streaming.rb +29 -49
  30. data/lib/action_controller/metal/default_headers.rb +17 -0
  31. data/lib/action_controller/metal/etag_with_flash.rb +18 -0
  32. data/lib/action_controller/metal/etag_with_template_digest.rb +20 -13
  33. data/lib/action_controller/metal/exceptions.rb +30 -15
  34. data/lib/action_controller/metal/flash.rb +9 -8
  35. data/lib/action_controller/metal/force_ssl.rb +23 -62
  36. data/lib/action_controller/metal/head.rb +22 -20
  37. data/lib/action_controller/metal/helpers.rb +26 -17
  38. data/lib/action_controller/metal/http_authentication.rb +76 -70
  39. data/lib/action_controller/metal/implicit_render.rb +53 -9
  40. data/lib/action_controller/metal/instrumentation.rb +22 -27
  41. data/lib/action_controller/metal/live.rb +101 -119
  42. data/lib/action_controller/metal/mime_responds.rb +44 -46
  43. data/lib/action_controller/metal/parameter_encoding.rb +51 -0
  44. data/lib/action_controller/metal/params_wrapper.rb +74 -63
  45. data/lib/action_controller/metal/redirecting.rb +53 -32
  46. data/lib/action_controller/metal/renderers.rb +87 -44
  47. data/lib/action_controller/metal/rendering.rb +72 -51
  48. data/lib/action_controller/metal/request_forgery_protection.rb +217 -97
  49. data/lib/action_controller/metal/rescue.rb +9 -16
  50. data/lib/action_controller/metal/streaming.rb +12 -11
  51. data/lib/action_controller/metal/strong_parameters.rb +619 -183
  52. data/lib/action_controller/metal/testing.rb +2 -17
  53. data/lib/action_controller/metal/url_for.rb +19 -10
  54. data/lib/action_controller/metal.rb +104 -87
  55. data/lib/action_controller/railtie.rb +28 -10
  56. data/lib/action_controller/railties/helpers.rb +3 -1
  57. data/lib/action_controller/renderer.rb +130 -0
  58. data/lib/action_controller/template_assertions.rb +11 -0
  59. data/lib/action_controller/test_case.rb +286 -418
  60. data/lib/action_controller.rb +33 -21
  61. data/lib/action_dispatch/http/cache.rb +100 -51
  62. data/lib/action_dispatch/http/content_disposition.rb +45 -0
  63. data/lib/action_dispatch/http/content_security_policy.rb +282 -0
  64. data/lib/action_dispatch/http/filter_parameters.rb +31 -24
  65. data/lib/action_dispatch/http/filter_redirect.rb +10 -12
  66. data/lib/action_dispatch/http/headers.rb +54 -22
  67. data/lib/action_dispatch/http/mime_negotiation.rb +61 -45
  68. data/lib/action_dispatch/http/mime_type.rb +141 -122
  69. data/lib/action_dispatch/http/mime_types.rb +20 -6
  70. data/lib/action_dispatch/http/parameter_filter.rb +8 -68
  71. data/lib/action_dispatch/http/parameters.rb +107 -39
  72. data/lib/action_dispatch/http/rack_cache.rb +2 -0
  73. data/lib/action_dispatch/http/request.rb +204 -117
  74. data/lib/action_dispatch/http/response.rb +248 -114
  75. data/lib/action_dispatch/http/upload.rb +21 -7
  76. data/lib/action_dispatch/http/url.rb +181 -100
  77. data/lib/action_dispatch/journey/formatter.rb +56 -34
  78. data/lib/action_dispatch/journey/gtg/builder.rb +7 -6
  79. data/lib/action_dispatch/journey/gtg/simulator.rb +3 -9
  80. data/lib/action_dispatch/journey/gtg/transition_table.rb +17 -17
  81. data/lib/action_dispatch/journey/nfa/builder.rb +5 -3
  82. data/lib/action_dispatch/journey/nfa/dot.rb +13 -13
  83. data/lib/action_dispatch/journey/nfa/simulator.rb +3 -3
  84. data/lib/action_dispatch/journey/nfa/transition_table.rb +5 -49
  85. data/lib/action_dispatch/journey/nodes/node.rb +25 -12
  86. data/lib/action_dispatch/journey/parser.rb +23 -22
  87. data/lib/action_dispatch/journey/parser.y +3 -2
  88. data/lib/action_dispatch/journey/parser_extras.rb +12 -4
  89. data/lib/action_dispatch/journey/path/pattern.rb +55 -46
  90. data/lib/action_dispatch/journey/route.rb +107 -28
  91. data/lib/action_dispatch/journey/router/utils.rb +25 -16
  92. data/lib/action_dispatch/journey/router.rb +35 -27
  93. data/lib/action_dispatch/journey/routes.rb +17 -17
  94. data/lib/action_dispatch/journey/scanner.rb +26 -17
  95. data/lib/action_dispatch/journey/visitors.rb +98 -54
  96. data/lib/action_dispatch/journey.rb +7 -5
  97. data/lib/action_dispatch/middleware/actionable_exceptions.rb +39 -0
  98. data/lib/action_dispatch/middleware/callbacks.rb +3 -6
  99. data/lib/action_dispatch/middleware/cookies.rb +292 -203
  100. data/lib/action_dispatch/middleware/debug_exceptions.rb +142 -63
  101. data/lib/action_dispatch/middleware/debug_locks.rb +124 -0
  102. data/lib/action_dispatch/middleware/debug_view.rb +66 -0
  103. data/lib/action_dispatch/middleware/exception_wrapper.rb +102 -70
  104. data/lib/action_dispatch/middleware/executor.rb +21 -0
  105. data/lib/action_dispatch/middleware/flash.rb +78 -54
  106. data/lib/action_dispatch/middleware/host_authorization.rb +101 -0
  107. data/lib/action_dispatch/middleware/public_exceptions.rb +32 -27
  108. data/lib/action_dispatch/middleware/reloader.rb +5 -91
  109. data/lib/action_dispatch/middleware/remote_ip.rb +48 -41
  110. data/lib/action_dispatch/middleware/request_id.rb +17 -9
  111. data/lib/action_dispatch/middleware/session/abstract_store.rb +41 -26
  112. data/lib/action_dispatch/middleware/session/cache_store.rb +24 -14
  113. data/lib/action_dispatch/middleware/session/cookie_store.rb +72 -73
  114. data/lib/action_dispatch/middleware/session/mem_cache_store.rb +8 -2
  115. data/lib/action_dispatch/middleware/show_exceptions.rb +26 -23
  116. data/lib/action_dispatch/middleware/ssl.rb +113 -35
  117. data/lib/action_dispatch/middleware/stack.rb +64 -41
  118. data/lib/action_dispatch/middleware/static.rb +57 -51
  119. data/lib/action_dispatch/middleware/templates/rescues/_actions.html.erb +13 -0
  120. data/lib/action_dispatch/middleware/templates/rescues/_actions.text.erb +0 -0
  121. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +4 -14
  122. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +1 -1
  123. data/lib/action_dispatch/middleware/templates/rescues/{_source.erb → _source.html.erb} +4 -2
  124. data/lib/action_dispatch/middleware/templates/rescues/_source.text.erb +8 -0
  125. data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +45 -35
  126. data/lib/action_dispatch/middleware/templates/rescues/blocked_host.html.erb +7 -0
  127. data/lib/action_dispatch/middleware/templates/rescues/blocked_host.text.erb +5 -0
  128. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +26 -4
  129. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +1 -1
  130. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +24 -0
  131. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb +15 -0
  132. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +5 -0
  133. data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb +19 -0
  134. data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.text.erb +3 -0
  135. data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +2 -2
  136. data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +1 -1
  137. data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +3 -3
  138. data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +1 -1
  139. data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +4 -4
  140. data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +67 -64
  141. data/lib/action_dispatch/railtie.rb +26 -13
  142. data/lib/action_dispatch/request/session.rb +114 -60
  143. data/lib/action_dispatch/request/utils.rb +67 -24
  144. data/lib/action_dispatch/routing/endpoint.rb +9 -2
  145. data/lib/action_dispatch/routing/inspector.rb +140 -102
  146. data/lib/action_dispatch/routing/mapper.rb +762 -455
  147. data/lib/action_dispatch/routing/polymorphic_routes.rb +161 -142
  148. data/lib/action_dispatch/routing/redirection.rb +36 -26
  149. data/lib/action_dispatch/routing/route_set.rb +322 -298
  150. data/lib/action_dispatch/routing/routes_proxy.rb +32 -5
  151. data/lib/action_dispatch/routing/url_for.rb +65 -26
  152. data/lib/action_dispatch/routing.rb +36 -36
  153. data/lib/action_dispatch/system_test_case.rb +185 -0
  154. data/lib/action_dispatch/system_testing/browser.rb +80 -0
  155. data/lib/action_dispatch/system_testing/driver.rb +68 -0
  156. data/lib/action_dispatch/system_testing/server.rb +31 -0
  157. data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +97 -0
  158. data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +32 -0
  159. data/lib/action_dispatch/testing/assertion_response.rb +46 -0
  160. data/lib/action_dispatch/testing/assertions/response.rb +44 -20
  161. data/lib/action_dispatch/testing/assertions/routing.rb +44 -28
  162. data/lib/action_dispatch/testing/assertions.rb +6 -4
  163. data/lib/action_dispatch/testing/integration.rb +375 -215
  164. data/lib/action_dispatch/testing/request_encoder.rb +55 -0
  165. data/lib/action_dispatch/testing/test_process.rb +28 -22
  166. data/lib/action_dispatch/testing/test_request.rb +27 -34
  167. data/lib/action_dispatch/testing/test_response.rb +11 -11
  168. data/lib/action_dispatch.rb +33 -20
  169. data/lib/action_pack/gem_version.rb +6 -4
  170. data/lib/action_pack/version.rb +3 -1
  171. data/lib/action_pack.rb +4 -2
  172. metadata +71 -40
  173. data/lib/action_controller/metal/hide_actions.rb +0 -40
  174. data/lib/action_controller/metal/rack_delegation.rb +0 -32
  175. data/lib/action_controller/middleware.rb +0 -39
  176. data/lib/action_controller/model_naming.rb +0 -12
  177. data/lib/action_dispatch/journey/backwards.rb +0 -5
  178. data/lib/action_dispatch/journey/router/strexp.rb +0 -27
  179. data/lib/action_dispatch/middleware/params_parser.rb +0 -60
  180. data/lib/action_dispatch/testing/assertions/dom.rb +0 -3
  181. data/lib/action_dispatch/testing/assertions/selector.rb +0 -3
  182. data/lib/action_dispatch/testing/assertions/tag.rb +0 -3
@@ -1,4 +1,6 @@
1
- require 'action_dispatch/journey/nfa/dot'
1
+ # frozen_string_literal: true
2
+
3
+ require "action_dispatch/journey/nfa/dot"
2
4
 
3
5
  module ActionDispatch
4
6
  module Journey # :nodoc:
@@ -12,7 +14,7 @@ module ActionDispatch
12
14
  @regexp_states = {}
13
15
  @string_states = {}
14
16
  @accepting = {}
15
- @memos = Hash.new { |h,k| h[k] = [] }
17
+ @memos = Hash.new { |h, k| h[k] = [] }
16
18
  end
17
19
 
18
20
  def add_accepting(state)
@@ -56,7 +58,7 @@ module ActionDispatch
56
58
  end
57
59
 
58
60
  def as_json(options = nil)
59
- simple_regexp = Hash.new { |h,k| h[k] = {} }
61
+ simple_regexp = Hash.new { |h, k| h[k] = {} }
60
62
 
61
63
  @regexp_states.each do |from, hash|
62
64
  hash.each do |re, to|
@@ -72,20 +74,20 @@ module ActionDispatch
72
74
  end
73
75
 
74
76
  def to_svg
75
- svg = IO.popen('dot -Tsvg', 'w+') { |f|
77
+ svg = IO.popen("dot -Tsvg", "w+") { |f|
76
78
  f.write(to_dot)
77
79
  f.close_write
78
80
  f.readlines
79
81
  }
80
82
  3.times { svg.shift }
81
- svg.join.sub(/width="[^"]*"/, '').sub(/height="[^"]*"/, '')
83
+ svg.join.sub(/width="[^"]*"/, "").sub(/height="[^"]*"/, "")
82
84
  end
83
85
 
84
- def visualizer(paths, title = 'FSM')
85
- viz_dir = File.join File.dirname(__FILE__), '..', 'visualizer'
86
- fsm_js = File.read File.join(viz_dir, 'fsm.js')
87
- fsm_css = File.read File.join(viz_dir, 'fsm.css')
88
- erb = File.read File.join(viz_dir, 'index.html.erb')
86
+ def visualizer(paths, title = "FSM")
87
+ viz_dir = File.join __dir__, "..", "visualizer"
88
+ fsm_js = File.read File.join(viz_dir, "fsm.js")
89
+ fsm_css = File.read File.join(viz_dir, "fsm.css")
90
+ erb = File.read File.join(viz_dir, "index.html.erb")
89
91
  states = "function tt() { return #{to_json}; }"
90
92
 
91
93
  fun_routes = paths.sample(3).map do |ast|
@@ -93,10 +95,10 @@ module ActionDispatch
93
95
  case n
94
96
  when Nodes::Symbol
95
97
  case n.left
96
- when ':id' then rand(100).to_s
97
- when ':format' then %w{ xml json }.sample
98
+ when ":id" then rand(100).to_s
99
+ when ":format" then %w{ xml json }.sample
98
100
  else
99
- 'omg'
101
+ "omg"
100
102
  end
101
103
  when Nodes::Terminal then n.symbol
102
104
  else
@@ -109,13 +111,12 @@ module ActionDispatch
109
111
  svg = to_svg
110
112
  javascripts = [states, fsm_js]
111
113
 
112
- # Annoying hack for 1.9 warnings
113
114
  fun_routes = fun_routes
114
115
  stylesheets = stylesheets
115
116
  svg = svg
116
117
  javascripts = javascripts
117
118
 
118
- require 'erb'
119
+ require "erb"
119
120
  template = ERB.new erb
120
121
  template.result(binding)
121
122
  end
@@ -140,7 +141,6 @@ module ActionDispatch
140
141
  end
141
142
 
142
143
  private
143
-
144
144
  def states_hash_for(sym)
145
145
  case sym
146
146
  when String
@@ -148,7 +148,7 @@ module ActionDispatch
148
148
  when Regexp
149
149
  @regexp_states
150
150
  else
151
- raise ArgumentError, 'unknown symbol: %s' % sym.class
151
+ raise ArgumentError, "unknown symbol: %s" % sym.class
152
152
  end
153
153
  end
154
154
  end
@@ -1,5 +1,7 @@
1
- require 'action_dispatch/journey/nfa/transition_table'
2
- require 'action_dispatch/journey/gtg/transition_table'
1
+ # frozen_string_literal: true
2
+
3
+ require "action_dispatch/journey/nfa/transition_table"
4
+ require "action_dispatch/journey/gtg/transition_table"
3
5
 
4
6
  module ActionDispatch
5
7
  module Journey # :nodoc:
@@ -36,7 +38,7 @@ module ActionDispatch
36
38
  def visit_OR(node)
37
39
  from = @i += 1
38
40
  children = node.children.map { |c| visit(c) }
39
- to = @i += 1
41
+ to = @i += 1
40
42
 
41
43
  children.each do |child|
42
44
  @tt[from, child.first] = nil
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module ActionDispatch
4
4
  module Journey # :nodoc:
@@ -9,18 +9,18 @@ module ActionDispatch
9
9
  " #{from} -> #{to} [label=\"#{sym || 'ε'}\"];"
10
10
  }
11
11
 
12
- #memo_nodes = memos.values.flatten.map { |n|
13
- # label = n
14
- # if Journey::Route === n
15
- # label = "#{n.verb.source} #{n.path.spec}"
16
- # end
17
- # " #{n.object_id} [label=\"#{label}\", shape=box];"
18
- #}
19
- #memo_edges = memos.flat_map { |k, memos|
20
- # (memos || []).map { |v| " #{k} -> #{v.object_id};" }
21
- #}.uniq
12
+ # memo_nodes = memos.values.flatten.map { |n|
13
+ # label = n
14
+ # if Journey::Route === n
15
+ # label = "#{n.verb.source} #{n.path.spec}"
16
+ # end
17
+ # " #{n.object_id} [label=\"#{label}\", shape=box];"
18
+ # }
19
+ # memo_edges = memos.flat_map { |k, memos|
20
+ # (memos || []).map { |v| " #{k} -> #{v.object_id};" }
21
+ # }.uniq
22
22
 
23
- <<-eodot
23
+ <<-eodot
24
24
  digraph nfa {
25
25
  rankdir=LR;
26
26
  node [shape = doublecircle];
@@ -28,7 +28,7 @@ digraph nfa {
28
28
  node [shape = circle];
29
29
  #{edges.join "\n"}
30
30
  }
31
- eodot
31
+ eodot
32
32
  end
33
33
  end
34
34
  end
@@ -1,4 +1,6 @@
1
- require 'strscan'
1
+ # frozen_string_literal: true
2
+
3
+ require "strscan"
2
4
 
3
5
  module ActionDispatch
4
6
  module Journey # :nodoc:
@@ -23,8 +25,6 @@ module ActionDispatch
23
25
  state = tt.eclosure(0)
24
26
  until input.eos?
25
27
  sym = input.scan(%r([/.?]|[^/.?]+))
26
-
27
- # FIXME: tt.eclosure is not needed for the GTG
28
28
  state = tt.eclosure(tt.move(state, sym))
29
29
  end
30
30
 
@@ -1,4 +1,6 @@
1
- require 'action_dispatch/journey/nfa/dot'
1
+ # frozen_string_literal: true
2
+
3
+ require "action_dispatch/journey/nfa/dot"
2
4
 
3
5
  module ActionDispatch
4
6
  module Journey # :nodoc:
@@ -10,7 +12,7 @@ module ActionDispatch
10
12
  attr_reader :memos
11
13
 
12
14
  def initialize
13
- @table = Hash.new { |h,f| h[f] = {} }
15
+ @table = Hash.new { |h, f| h[f] = {} }
14
16
  @memos = {}
15
17
  @accepting = nil
16
18
  @inverted = nil
@@ -45,51 +47,6 @@ module ActionDispatch
45
47
  (@table.keys + @table.values.flat_map(&:keys)).uniq
46
48
  end
47
49
 
48
- # Returns a generalized transition graph with reduced states. The states
49
- # are reduced like a DFA, but the table must be simulated like an NFA.
50
- #
51
- # Edges of the GTG are regular expressions.
52
- def generalized_table
53
- gt = GTG::TransitionTable.new
54
- marked = {}
55
- state_id = Hash.new { |h,k| h[k] = h.length }
56
- alphabet = self.alphabet
57
-
58
- stack = [eclosure(0)]
59
-
60
- until stack.empty?
61
- state = stack.pop
62
- next if marked[state] || state.empty?
63
-
64
- marked[state] = true
65
-
66
- alphabet.each do |alpha|
67
- next_state = eclosure(following_states(state, alpha))
68
- next if next_state.empty?
69
-
70
- gt[state_id[state], state_id[next_state]] = alpha
71
- stack << next_state
72
- end
73
- end
74
-
75
- final_groups = state_id.keys.find_all { |s|
76
- s.sort.last == accepting
77
- }
78
-
79
- final_groups.each do |states|
80
- id = state_id[states]
81
-
82
- gt.add_accepting(id)
83
- save = states.find { |s|
84
- @memos.key?(s) && eclosure(s).sort.last == accepting
85
- }
86
-
87
- gt.add_memo(id, memo(save))
88
- end
89
-
90
- gt
91
- end
92
-
93
50
  # Returns set of NFA states to which there is a transition on ast symbol
94
51
  # +a+ from some state +s+ in +t+.
95
52
  def following_states(t, a)
@@ -107,7 +64,7 @@ module ActionDispatch
107
64
  end
108
65
 
109
66
  def alphabet
110
- inverted.values.flat_map(&:keys).compact.uniq.sort_by { |x| x.to_s }
67
+ inverted.values.flat_map(&:keys).compact.uniq.sort_by(&:to_s)
111
68
  end
112
69
 
113
70
  # Returns a set of NFA states reachable from some NFA state +s+ in set
@@ -137,7 +94,6 @@ module ActionDispatch
137
94
  end
138
95
 
139
96
  private
140
-
141
97
  def inverted
142
98
  return @inverted if @inverted
143
99
 
@@ -1,4 +1,6 @@
1
- require 'action_dispatch/journey/visitors'
1
+ # frozen_string_literal: true
2
+
3
+ require "action_dispatch/journey/visitors"
2
4
 
3
5
  module ActionDispatch
4
6
  module Journey # :nodoc:
@@ -14,15 +16,15 @@ module ActionDispatch
14
16
  end
15
17
 
16
18
  def each(&block)
17
- Visitors::Each.new(block).accept(self)
19
+ Visitors::Each::INSTANCE.accept(self, block)
18
20
  end
19
21
 
20
22
  def to_s
21
- Visitors::String.new.accept(self)
23
+ Visitors::String::INSTANCE.accept(self, "")
22
24
  end
23
25
 
24
26
  def to_dot
25
- Visitors::Dot.new.accept(self)
27
+ Visitors::Dot::INSTANCE.accept(self)
26
28
  end
27
29
 
28
30
  def to_sym
@@ -30,7 +32,7 @@ module ActionDispatch
30
32
  end
31
33
 
32
34
  def name
33
- left.tr '*:', ''
35
+ -left.tr("*:", "")
34
36
  end
35
37
 
36
38
  def type
@@ -39,10 +41,15 @@ module ActionDispatch
39
41
 
40
42
  def symbol?; false; end
41
43
  def literal?; false; end
44
+ def terminal?; false; end
45
+ def star?; false; end
46
+ def cat?; false; end
47
+ def group?; false; end
42
48
  end
43
49
 
44
50
  class Terminal < Node # :nodoc:
45
51
  alias :symbol :left
52
+ def terminal?; true; end
46
53
  end
47
54
 
48
55
  class Literal < Terminal # :nodoc:
@@ -58,28 +65,31 @@ module ActionDispatch
58
65
  def literal?; false; end
59
66
  end
60
67
 
61
- %w{ Symbol Slash Dot }.each do |t|
62
- class_eval <<-eoruby, __FILE__, __LINE__ + 1
63
- class #{t} < Terminal;
64
- def type; :#{t.upcase}; end
65
- end
66
- eoruby
68
+ class Slash < Terminal # :nodoc:
69
+ def type; :SLASH; end
70
+ end
71
+
72
+ class Dot < Terminal # :nodoc:
73
+ def type; :DOT; end
67
74
  end
68
75
 
69
76
  class Symbol < Terminal # :nodoc:
70
77
  attr_accessor :regexp
71
78
  alias :symbol :regexp
79
+ attr_reader :name
72
80
 
73
81
  DEFAULT_EXP = /[^\.\/\?]+/
74
82
  def initialize(left)
75
83
  super
76
84
  @regexp = DEFAULT_EXP
85
+ @name = -left.tr("*:", "")
77
86
  end
78
87
 
79
88
  def default_regexp?
80
89
  regexp == DEFAULT_EXP
81
90
  end
82
91
 
92
+ def type; :SYMBOL; end
83
93
  def symbol?; true; end
84
94
  end
85
95
 
@@ -89,13 +99,15 @@ module ActionDispatch
89
99
 
90
100
  class Group < Unary # :nodoc:
91
101
  def type; :GROUP; end
102
+ def group?; true; end
92
103
  end
93
104
 
94
105
  class Star < Unary # :nodoc:
106
+ def star?; true; end
95
107
  def type; :STAR; end
96
108
 
97
109
  def name
98
- left.name.tr '*:', ''
110
+ left.name.tr "*:", ""
99
111
  end
100
112
  end
101
113
 
@@ -111,6 +123,7 @@ module ActionDispatch
111
123
  end
112
124
 
113
125
  class Cat < Binary # :nodoc:
126
+ def cat?; true; end
114
127
  def type; :CAT; end
115
128
  end
116
129
 
@@ -1,32 +1,33 @@
1
1
  #
2
2
  # DO NOT MODIFY!!!!
3
- # This file is automatically generated by Racc 1.4.11
4
- # from Racc grammer file "".
3
+ # This file is automatically generated by Racc 1.4.14
4
+ # from Racc grammar file "".
5
5
  #
6
6
 
7
7
  require 'racc/parser.rb'
8
8
 
9
+ # :stopdoc:
9
10
 
10
- require 'action_dispatch/journey/parser_extras'
11
+ require "action_dispatch/journey/parser_extras"
11
12
  module ActionDispatch
12
13
  module Journey
13
14
  class Parser < Racc::Parser
14
15
  ##### State transition tables begin ###
15
16
 
16
17
  racc_action_table = [
17
- 13, 15, 14, 7, 21, 16, 8, 19, 13, 15,
18
- 14, 7, 17, 16, 8, 13, 15, 14, 7, 24,
19
- 16, 8, 13, 15, 14, 7, 19, 16, 8 ]
18
+ 13, 15, 14, 7, 19, 16, 8, 19, 13, 15,
19
+ 14, 7, 17, 16, 8, 13, 15, 14, 7, 21,
20
+ 16, 8, 13, 15, 14, 7, 24, 16, 8 ]
20
21
 
21
22
  racc_action_check = [
22
- 2, 2, 2, 2, 17, 2, 2, 2, 0, 0,
23
- 0, 0, 1, 0, 0, 19, 19, 19, 19, 20,
24
- 19, 19, 7, 7, 7, 7, 22, 7, 7 ]
23
+ 2, 2, 2, 2, 22, 2, 2, 2, 19, 19,
24
+ 19, 19, 1, 19, 19, 7, 7, 7, 7, 17,
25
+ 7, 7, 0, 0, 0, 0, 20, 0, 0 ]
25
26
 
26
27
  racc_action_pointer = [
27
- 6, 12, -2, nil, nil, nil, nil, 20, nil, nil,
28
- nil, nil, nil, nil, nil, nil, nil, 4, nil, 13,
29
- 13, nil, 17, nil, nil ]
28
+ 20, 12, -2, nil, nil, nil, nil, 13, nil, nil,
29
+ nil, nil, nil, nil, nil, nil, nil, 19, nil, 6,
30
+ 20, nil, -5, nil, nil ]
30
31
 
31
32
  racc_action_default = [
32
33
  -19, -19, -2, -3, -4, -5, -6, -19, -10, -11,
@@ -134,11 +135,11 @@ Racc_debug_parser = false
134
135
  # reduce 0 omitted
135
136
 
136
137
  def _reduce_1(val, _values)
137
- Cat.new(val.first, val.last)
138
+ Cat.new(val.first, val.last)
138
139
  end
139
140
 
140
141
  def _reduce_2(val, _values)
141
- val.first
142
+ val.first
142
143
  end
143
144
 
144
145
  # reduce 3 omitted
@@ -150,19 +151,19 @@ end
150
151
  # reduce 6 omitted
151
152
 
152
153
  def _reduce_7(val, _values)
153
- Group.new(val[1])
154
+ Group.new(val[1])
154
155
  end
155
156
 
156
157
  def _reduce_8(val, _values)
157
- Or.new([val.first, val.last])
158
+ Or.new([val.first, val.last])
158
159
  end
159
160
 
160
161
  def _reduce_9(val, _values)
161
- Or.new([val.first, val.last])
162
+ Or.new([val.first, val.last])
162
163
  end
163
164
 
164
165
  def _reduce_10(val, _values)
165
- Star.new(Symbol.new(val.last))
166
+ Star.new(Symbol.new(val.last))
166
167
  end
167
168
 
168
169
  # reduce 11 omitted
@@ -174,19 +175,19 @@ end
174
175
  # reduce 14 omitted
175
176
 
176
177
  def _reduce_15(val, _values)
177
- Slash.new('/')
178
+ Slash.new(val.first)
178
179
  end
179
180
 
180
181
  def _reduce_16(val, _values)
181
- Symbol.new(val.first)
182
+ Symbol.new(val.first)
182
183
  end
183
184
 
184
185
  def _reduce_17(val, _values)
185
- Literal.new(val.first)
186
+ Literal.new(val.first)
186
187
  end
187
188
 
188
189
  def _reduce_18(val, _values)
189
- Dot.new(val.first)
190
+ Dot.new(val.first)
190
191
  end
191
192
 
192
193
  def _reduce_none(val, _values)
@@ -30,7 +30,7 @@ rule
30
30
  | dot
31
31
  ;
32
32
  slash
33
- : SLASH { Slash.new('/') }
33
+ : SLASH { Slash.new(val.first) }
34
34
  ;
35
35
  symbol
36
36
  : SYMBOL { Symbol.new(val.first) }
@@ -45,5 +45,6 @@ rule
45
45
  end
46
46
 
47
47
  ---- header
48
+ # :stopdoc:
48
49
 
49
- require 'action_dispatch/journey/parser_extras'
50
+ require "action_dispatch/journey/parser_extras"
@@ -1,11 +1,18 @@
1
- require 'action_dispatch/journey/scanner'
2
- require 'action_dispatch/journey/nodes/node'
1
+ # frozen_string_literal: true
2
+
3
+ require "action_dispatch/journey/scanner"
4
+ require "action_dispatch/journey/nodes/node"
3
5
 
4
6
  module ActionDispatch
5
- module Journey # :nodoc:
6
- class Parser < Racc::Parser # :nodoc:
7
+ # :stopdoc:
8
+ module Journey
9
+ class Parser < Racc::Parser
7
10
  include Journey::Nodes
8
11
 
12
+ def self.parse(string)
13
+ new.parse string
14
+ end
15
+
9
16
  def initialize
10
17
  @scanner = Scanner.new
11
18
  end
@@ -20,4 +27,5 @@ module ActionDispatch
20
27
  end
21
28
  end
22
29
  end
30
+ # :startdoc:
23
31
  end