Merge pull request #35919 from Shopify/simplify-define_url_helper

Simplify and fasten NamedRouteCollection#define_url_helper
This commit is contained in:
Rafael França 2019-04-11 18:43:58 -04:00 committed by GitHub
commit 98e10c2dea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -317,18 +317,16 @@ def handle_positional_args(controller_options, inner_options, args, result, path
#
def define_url_helper(mod, route, name, opts, route_key, url_strategy)
helper = UrlHelper.create(route, opts, route_key, url_strategy)
mod.module_eval do
define_method(name) do |*args|
last = args.last
options = \
case last
when Hash
args.pop
when ActionController::Parameters
args.pop.to_h
end
helper.call self, args, options
end
mod.define_method(name) do |*args|
last = args.last
options = \
case last
when Hash
args.pop
when ActionController::Parameters
args.pop.to_h
end
helper.call self, args, options
end
end
end