Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

refactor route_set `generate_extras` functionality

The result of Generator with or without the @extras instance variable set contains the desired information. Rather than preserving state when initializing the original object, we can simply extract the keys from the resultant parameters.

ATP Actionpack, railties
  • Loading branch information...
commit cc57b2a422a18f22f8ecf6912ebfab0da0ac3c8a 1 parent 0b6175a
Richard Schneeman authored

Showing 1 changed file with 9 additions and 17 deletions. Show diff stats Hide diff stats

  1. +9 17 actionpack/lib/action_dispatch/routing/route_set.rb
26 actionpack/lib/action_dispatch/routing/route_set.rb
@@ -438,12 +438,11 @@ class Generator #:nodoc:
438 438
439 439 attr_reader :options, :recall, :set, :named_route
440 440
441   - def initialize(options, recall, set, extras = false)
  441 + def initialize(options, recall, set)
442 442 @named_route = options.delete(:use_route)
443 443 @options = options.dup
444 444 @recall = recall.dup
445 445 @set = set
446   - @extras = extras
447 446
448 447 normalize_options!
449 448 normalize_controller_action_id!
@@ -526,20 +525,12 @@ def handle_nil_action!
526 525 recall[:action] = options.delete(:action) if options[:action] == 'index'
527 526 end
528 527
  528 + # Generates a path from routes, returns [path, params]
  529 + # if no path is returned the formatter will raise Journey::Router::RoutingError
529 530 def generate
530   - path, params = @set.formatter.generate(:path_info, named_route, options, recall, PARAMETERIZE)
531   -
532   - raise_routing_error unless path
533   -
534   - return [path, params.keys] if @extras
535   -
536   - [path, params]
  531 + @set.formatter.generate(:path_info, named_route, options, recall, PARAMETERIZE)
537 532 rescue Journey::Router::RoutingError => e
538   - raise_routing_error(e.message)
539   - end
540   -
541   - def raise_routing_error(message)
542   - raise ActionController::UrlGenerationError, "No route matches #{options.inspect} #{message}"
  533 + raise ActionController::UrlGenerationError, "No route matches #{options.inspect} #{e.message}"
543 534 end
544 535
545 536 def different_controller?
@@ -564,11 +555,12 @@ def extra_keys(options, recall={})
564 555 end
565 556
566 557 def generate_extras(options, recall={})
567   - generate(options, recall, true)
  558 + path, params = generate(options, recall)
  559 + return path, params.keys
568 560 end
569 561
570   - def generate(options, recall = {}, extras = false)
571   - Generator.new(options, recall, self, extras).generate
  562 + def generate(options, recall = {})
  563 + Generator.new(options, recall, self).generate
572 564 end
573 565
574 566 RESERVED_OPTIONS = [:host, :protocol, :port, :subdomain, :domain, :tld_length,

0 comments on commit cc57b2a

Please sign in to comment.
Something went wrong with that request. Please try again.