diff options
author | Xavier Noria <fxn@hashref.com> | 2017-07-02 13:50:25 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-02 13:50:25 -0700 |
commit | 92c29d82eb2f323bb1338a039229a66057a7d137 (patch) | |
tree | 050eea5a719faa416b64b804617f8755b6500e09 /actionpack/lib/action_dispatch/routing | |
parent | f851e1f705f26d8f92f0fc1b265b20bc389d23cb (diff) | |
parent | f443460670576cd82a806a851b7124479e8325c9 (diff) | |
download | rails-92c29d82eb2f323bb1338a039229a66057a7d137.tar.gz rails-92c29d82eb2f323bb1338a039229a66057a7d137.tar.bz2 rails-92c29d82eb2f323bb1338a039229a66057a7d137.zip |
Merge branch 'master' into require_relative_2017
Diffstat (limited to 'actionpack/lib/action_dispatch/routing')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/route_set.rb | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 1be2bc8022..ebe809f64e 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -73,7 +73,6 @@ module ActionDispatch @routes = {} @path_helpers = Set.new @url_helpers = Set.new - @custom_helpers = Set.new @url_helpers_module = Module.new @path_helpers_module = Module.new end @@ -96,23 +95,9 @@ module ActionDispatch @url_helpers_module.send :remove_method, helper end - @custom_helpers.each do |helper| - path_name = :"#{helper}_path" - url_name = :"#{helper}_url" - - if @path_helpers_module.method_defined?(path_name) - @path_helpers_module.send :remove_method, path_name - end - - if @url_helpers_module.method_defined?(url_name) - @url_helpers_module.send :remove_method, url_name - end - end - @routes.clear @path_helpers.clear @url_helpers.clear - @custom_helpers.clear end def add(name, route) @@ -158,21 +143,29 @@ module ActionDispatch routes.length end + # Given a +name+, defines name_path and name_url helpers. + # Used by 'direct', 'resolve', and 'polymorphic' route helpers. def add_url_helper(name, defaults, &block) - @custom_helpers << name helper = CustomUrlHelper.new(name, defaults, &block) + path_name = :"#{name}_path" + url_name = :"#{name}_url" @path_helpers_module.module_eval do - define_method(:"#{name}_path") do |*args| + define_method(path_name) do |*args| helper.call(self, args, true) end end @url_helpers_module.module_eval do - define_method(:"#{name}_url") do |*args| + define_method(url_name) do |*args| helper.call(self, args, false) end end + + @path_helpers << path_name + @url_helpers << url_name + + self end class UrlHelper |