From cc57b2a422a18f22f8ecf6912ebfab0da0ac3c8a Mon Sep 17 00:00:00 2001 From: schneems Date: Mon, 27 Aug 2012 14:39:43 -0500 Subject: 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 --- .../lib/action_dispatch/routing/route_set.rb | 26 ++++++++-------------- 1 file changed, 9 insertions(+), 17 deletions(-) (limited to 'actionpack') 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, -- cgit v1.2.3