aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschneems <richard.schneeman@gmail.com>2012-08-27 14:39:43 -0500
committerschneems <richard.schneeman@gmail.com>2012-08-28 08:53:45 -0700
commitcc57b2a422a18f22f8ecf6912ebfab0da0ac3c8a (patch)
tree2e28d0f46250e5531602f85647f08af170efea97
parent0b6175ac2df96ebfca1baac89c20deaa13e61142 (diff)
downloadrails-cc57b2a422a18f22f8ecf6912ebfab0da0ac3c8a.tar.gz
rails-cc57b2a422a18f22f8ecf6912ebfab0da0ac3c8a.tar.bz2
rails-cc57b2a422a18f22f8ecf6912ebfab0da0ac3c8a.zip
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
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb26
1 files changed, 9 insertions, 17 deletions
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index bb1323c74e..1fe40d8458 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -438,12 +438,11 @@ module ActionDispatch
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 @@ module ActionDispatch
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 @@ module ActionDispatch
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,