Permalink
Browse files

extract inner options before delegating to the helper

If we extract the options from the user facing method call ASAP, then we
can simplify internal logic.
  • Loading branch information...
1 parent d12b30f commit f636652dd52ed36f7438c0436679c987cdfefb82 @tenderlove tenderlove committed Jul 16, 2014
Showing with 13 additions and 7 deletions.
  1. +13 −7 actionpack/lib/action_dispatch/routing/route_set.rb
View
20 actionpack/lib/action_dispatch/routing/route_set.rb
@@ -155,8 +155,8 @@ def initialize(route, options)
@arg_size = @required_parts.size
end
- def call(t, args)
- if args.size == arg_size && !args.last.is_a?(Hash) && optimize_routes_generation?(t)
+ def call(t, args, inner_options)
+ if args.size == arg_size && !inner_options && optimize_routes_generation?(t)
options = t.url_options.merge @options
options[:path] = optimized_helper(args)
ActionDispatch::Http::URL.url_for(options)
@@ -207,15 +207,19 @@ def initialize(route, options)
@route = route
end
- def call(t, args)
+ def call(t, args, inner_options)
controller_options = t.url_options
options = controller_options.merge @options
- hash = handle_positional_args(controller_options, args, options, @segment_keys)
+ hash = handle_positional_args(controller_options,
+ inner_options || {},
+ args,
+ options,
+ @segment_keys)
+
t._routes.url_for(hash)
end
- def handle_positional_args(controller_options, args, result, path_params)
- inner_options = args.extract_options!
+ def handle_positional_args(controller_options, inner_options, args, result, path_params)
if args.size > 0
if args.size < path_params.size - 1 # take format into account
@@ -251,7 +255,9 @@ def define_url_helper(route, name, options)
@module.remove_possible_method name
@module.module_eval do
define_method(name) do |*args|
- helper.call self, args
+ options = nil
+ options = args.pop if args.last.is_a? Hash
+ helper.call self, args, options
end
end

0 comments on commit f636652

Please sign in to comment.