diff options
Diffstat (limited to 'actionpack/lib/action_dispatch/journey')
10 files changed, 45 insertions, 31 deletions
diff --git a/actionpack/lib/action_dispatch/journey/formatter.rb b/actionpack/lib/action_dispatch/journey/formatter.rb index a289c34e8b..20ff4441a0 100644 --- a/actionpack/lib/action_dispatch/journey/formatter.rb +++ b/actionpack/lib/action_dispatch/journey/formatter.rb @@ -1,10 +1,11 @@ require "action_controller/metal/exceptions" module ActionDispatch + # :stopdoc: module Journey # The Formatter class is used for formatting URLs. For example, parameters # passed to +url_for+ in Rails will eventually call Formatter#generate. - class Formatter # :nodoc: + class Formatter attr_reader :routes def initialize(routes) @@ -44,8 +45,12 @@ module ActionDispatch return [route.format(parameterized_parts), params] end - message = "No route matches #{Hash[constraints.sort_by { |k,v| k.to_s }].inspect}" - message << " missing required keys: #{missing_keys.sort.inspect}" if missing_keys && !missing_keys.empty? + unmatched_keys = (missing_keys || []) & constraints.keys + missing_keys = (missing_keys || []) - unmatched_keys + + message = "No route matches #{Hash[constraints.sort_by { |k, v| k.to_s }].inspect}" + message << ", missing required keys: #{missing_keys.sort.inspect}" if missing_keys && !missing_keys.empty? + message << ", possible unmatched constraints: #{unmatched_keys.sort.inspect}" if unmatched_keys && !unmatched_keys.empty? raise ActionController::UrlGenerationError, message end @@ -174,4 +179,5 @@ module ActionDispatch end end end + # :startdoc: end diff --git a/actionpack/lib/action_dispatch/journey/gtg/builder.rb b/actionpack/lib/action_dispatch/journey/gtg/builder.rb index 9990c66627..0f8bed89bf 100644 --- a/actionpack/lib/action_dispatch/journey/gtg/builder.rb +++ b/actionpack/lib/action_dispatch/journey/gtg/builder.rb @@ -17,7 +17,7 @@ module ActionDispatch def transition_table dtrans = TransitionTable.new marked = {} - state_id = Hash.new { |h,k| h[k] = h.length } + state_id = Hash.new { |h, k| h[k] = h.length } start = firstpos(root) dstates = [start] diff --git a/actionpack/lib/action_dispatch/journey/gtg/transition_table.rb b/actionpack/lib/action_dispatch/journey/gtg/transition_table.rb index 0be18dc26f..beb9f1ef3b 100644 --- a/actionpack/lib/action_dispatch/journey/gtg/transition_table.rb +++ b/actionpack/lib/action_dispatch/journey/gtg/transition_table.rb @@ -12,7 +12,7 @@ module ActionDispatch @regexp_states = {} @string_states = {} @accepting = {} - @memos = Hash.new { |h,k| h[k] = [] } + @memos = Hash.new { |h, k| h[k] = [] } end def add_accepting(state) @@ -56,7 +56,7 @@ module ActionDispatch end def as_json(options = nil) - simple_regexp = Hash.new { |h,k| h[k] = {} } + simple_regexp = Hash.new { |h, k| h[k] = {} } @regexp_states.each do |from, hash| hash.each do |re, to| diff --git a/actionpack/lib/action_dispatch/journey/nfa/builder.rb b/actionpack/lib/action_dispatch/journey/nfa/builder.rb index 19e5752ae5..532f765094 100644 --- a/actionpack/lib/action_dispatch/journey/nfa/builder.rb +++ b/actionpack/lib/action_dispatch/journey/nfa/builder.rb @@ -36,7 +36,7 @@ module ActionDispatch def visit_OR(node) from = @i += 1 children = node.children.map { |c| visit(c) } - to = @i += 1 + to = @i += 1 children.each do |child| @tt[from, child.first] = nil diff --git a/actionpack/lib/action_dispatch/journey/nfa/transition_table.rb b/actionpack/lib/action_dispatch/journey/nfa/transition_table.rb index 4737adc724..543a670da0 100644 --- a/actionpack/lib/action_dispatch/journey/nfa/transition_table.rb +++ b/actionpack/lib/action_dispatch/journey/nfa/transition_table.rb @@ -10,7 +10,7 @@ module ActionDispatch attr_reader :memos def initialize - @table = Hash.new { |h,f| h[f] = {} } + @table = Hash.new { |h, f| h[f] = {} } @memos = {} @accepting = nil @inverted = nil diff --git a/actionpack/lib/action_dispatch/journey/parser.rb b/actionpack/lib/action_dispatch/journey/parser.rb index 7ec9d63859..ee91b11b42 100644 --- a/actionpack/lib/action_dispatch/journey/parser.rb +++ b/actionpack/lib/action_dispatch/journey/parser.rb @@ -8,9 +8,10 @@ require "racc/parser.rb" require "action_dispatch/journey/parser_extras" module ActionDispatch + # :stopdoc: module Journey class Parser < Racc::Parser -##### State transition tables begin ### + ##### State transition tables begin ### racc_action_table = [ 13, 15, 14, 7, 21, 16, 8, 19, 13, 15, @@ -128,9 +129,9 @@ module ActionDispatch Racc_debug_parser = false -##### State transition tables end ##### + ##### State transition tables end ##### -# reduce 0 omitted + # reduce 0 omitted def _reduce_1(val, _values) Cat.new(val.first, val.last) @@ -140,13 +141,13 @@ module ActionDispatch val.first end -# reduce 3 omitted + # reduce 3 omitted -# reduce 4 omitted + # reduce 4 omitted -# reduce 5 omitted + # reduce 5 omitted -# reduce 6 omitted + # reduce 6 omitted def _reduce_7(val, _values) Group.new(val[1]) @@ -164,13 +165,13 @@ module ActionDispatch Star.new(Symbol.new(val.last)) end -# reduce 11 omitted + # reduce 11 omitted -# reduce 12 omitted + # reduce 12 omitted -# reduce 13 omitted + # reduce 13 omitted -# reduce 14 omitted + # reduce 14 omitted def _reduce_15(val, _values) Slash.new("/") @@ -193,4 +194,5 @@ module ActionDispatch end end # class Parser end # module Journey + # :startdoc: end # module ActionDispatch diff --git a/actionpack/lib/action_dispatch/journey/parser_extras.rb b/actionpack/lib/action_dispatch/journey/parser_extras.rb index ec26e634e8..4c7e82d93c 100644 --- a/actionpack/lib/action_dispatch/journey/parser_extras.rb +++ b/actionpack/lib/action_dispatch/journey/parser_extras.rb @@ -2,8 +2,9 @@ require "action_dispatch/journey/scanner" require "action_dispatch/journey/nodes/node" module ActionDispatch - module Journey # :nodoc: - class Parser < Racc::Parser # :nodoc: + # :stopdoc: + module Journey + class Parser < Racc::Parser include Journey::Nodes def self.parse(string) @@ -24,4 +25,5 @@ module ActionDispatch end end end + # :startdoc: end diff --git a/actionpack/lib/action_dispatch/journey/route.rb b/actionpack/lib/action_dispatch/journey/route.rb index a9713ff292..0cc8d83ac8 100644 --- a/actionpack/lib/action_dispatch/journey/route.rb +++ b/actionpack/lib/action_dispatch/journey/route.rb @@ -1,6 +1,7 @@ module ActionDispatch - module Journey # :nodoc: - class Route # :nodoc: + # :stopdoc: + module Journey + class Route attr_reader :app, :path, :defaults, :name, :precedence attr_reader :constraints, :internal @@ -80,9 +81,9 @@ module ActionDispatch end end - def requirements # :nodoc: + def requirements # needed for rails `rails routes` - @defaults.merge(path.requirements).delete_if { |_,v| + @defaults.merge(path.requirements).delete_if { |_, v| /.+?/ == v } end @@ -97,7 +98,7 @@ module ActionDispatch def score(constraints) required_keys = path.required_names - supplied_keys = constraints.map { |k,v| v && k.to_s }.compact + supplied_keys = constraints.map { |k, v| v && k.to_s }.compact return -1 unless (required_keys - supplied_keys).empty? @@ -123,7 +124,7 @@ module ActionDispatch end def required_defaults - @required_defaults ||= @defaults.dup.delete_if do |k,_| + @required_defaults ||= @defaults.dup.delete_if do |k, _| parts.include?(k) || !required_default?(k) end end @@ -176,4 +177,5 @@ module ActionDispatch end end end + # :startdoc: end diff --git a/actionpack/lib/action_dispatch/journey/router.rb b/actionpack/lib/action_dispatch/journey/router.rb index d0ef549335..084ae9325e 100644 --- a/actionpack/lib/action_dispatch/journey/router.rb +++ b/actionpack/lib/action_dispatch/journey/router.rb @@ -109,9 +109,9 @@ module ActionDispatch routes.sort_by!(&:precedence) routes.map! { |r| - match_data = r.path.match(req.path_info) + match_data = r.path.match(req.path_info) path_parameters = r.defaults.dup - match_data.names.zip(match_data.captures) { |name,val| + match_data.names.zip(match_data.captures) { |name, val| path_parameters[name.to_sym] = Utils.unescape_uri(val) if val } [match_data, path_parameters, r] diff --git a/actionpack/lib/action_dispatch/journey/visitors.rb b/actionpack/lib/action_dispatch/journey/visitors.rb index 452dc84cc5..cda859cba4 100644 --- a/actionpack/lib/action_dispatch/journey/visitors.rb +++ b/actionpack/lib/action_dispatch/journey/visitors.rb @@ -1,5 +1,6 @@ module ActionDispatch - module Journey # :nodoc: + # :stopdoc: + module Journey class Format ESCAPE_PATH = ->(value) { Router::Utils.escape_path(value) } ESCAPE_SEGMENT = ->(value) { Router::Utils.escape_segment(value) } @@ -21,7 +22,7 @@ module ActionDispatch @children = [] @parameters = [] - parts.each_with_index do |object,i| + parts.each_with_index do |object, i| case object when Journey::Format @children << i @@ -261,4 +262,5 @@ module ActionDispatch end end end + # :startdoc: end |