Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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 schneems authored
Showing with 9 additions and 17 deletions.
  1. +9 −17 actionpack/lib/action_dispatch/routing/route_set.rb
26 actionpack/lib/action_dispatch/routing/route_set.rb
View
@@ -438,12 +438,11 @@ class Generator #:nodoc:
attr_reader :options, :recall, :set, :named_route
- def initialize(options, recall, set, extras = false)
+ def initialize(options, recall, set)
@named_route = options.delete(:use_route)
@options = options.dup
@recall = recall.dup
@set = set
- @extras = extras
normalize_options!
normalize_controller_action_id!
@@ -526,20 +525,12 @@ def handle_nil_action!
recall[:action] = options.delete(:action) if options[:action] == 'index'
end
+ # Generates a path from routes, returns [path, params]
+ # if no path is returned the formatter will raise Journey::Router::RoutingError
def generate
- path, params = @set.formatter.generate(:path_info, named_route, options, recall, PARAMETERIZE)
-
- raise_routing_error unless path
-
- return [path, params.keys] if @extras
-
- [path, params]
+ @set.formatter.generate(:path_info, named_route, options, recall, PARAMETERIZE)
rescue Journey::Router::RoutingError => e
- raise_routing_error(e.message)
- end
-
- def raise_routing_error(message)
- raise ActionController::UrlGenerationError, "No route matches #{options.inspect} #{message}"
+ raise ActionController::UrlGenerationError, "No route matches #{options.inspect} #{e.message}"
end
def different_controller?
@@ -564,11 +555,12 @@ def extra_keys(options, recall={})
end
def generate_extras(options, recall={})
- generate(options, recall, true)
+ path, params = generate(options, recall)
+ return path, params.keys
end
- def generate(options, recall = {}, extras = false)
- Generator.new(options, recall, self, extras).generate
+ def generate(options, recall = {})
+ Generator.new(options, recall, self).generate
end
RESERVED_OPTIONS = [:host, :protocol, :port, :subdomain, :domain, :tld_length,
Please sign in to comment.
Something went wrong with that request. Please try again.