diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-07-29 11:48:14 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-07-29 11:48:14 -0700 |
commit | 0088b08dcaf16176c8f9364d1d786f0c3728d369 (patch) | |
tree | 97fc207e24e3d3e018b0768a81b8d7b5f1a8adbf | |
parent | 41931b8af1324f0edf6754fbbfe66433b0b02cf1 (diff) | |
download | rails-0088b08dcaf16176c8f9364d1d786f0c3728d369.tar.gz rails-0088b08dcaf16176c8f9364d1d786f0c3728d369.tar.bz2 rails-0088b08dcaf16176c8f9364d1d786f0c3728d369.zip |
helpers should be a Set so it doesn't grow unbounded
since helpers is a set, we can be confident about when to remove methods
from the module.
-rw-r--r-- | actionpack/lib/action_dispatch/routing/route_set.rb | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index aa0803e0e3..14c5d663a3 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -90,7 +90,7 @@ module ActionDispatch def initialize @routes = {} - @helpers = [] + @helpers = Set.new @module = Module.new end @@ -100,7 +100,7 @@ module ActionDispatch def clear! @helpers.each do |helper| - @module.remove_possible_method helper + @module.send :undef_method, helper end @routes.clear @@ -108,7 +108,11 @@ module ActionDispatch end def add(name, route) - routes[name.to_sym] = route + key = name.to_sym + if routes.key? key + undef_named_route_methods @module, name + end + routes[key] = route define_named_route_methods(@module, name, route) end @@ -256,7 +260,6 @@ module ActionDispatch def define_url_helper(mod, route, name, opts, route_key, url_strategy) helper = UrlHelper.create(route, opts, route_key, url_strategy) - mod.remove_possible_method name mod.module_eval do define_method(name) do |*args| options = nil @@ -272,6 +275,11 @@ module ActionDispatch define_url_helper mod, route, :"#{name}_path", route.defaults, name, PATH define_url_helper mod, route, :"#{name}_url", route.defaults, name, FULL end + + def undef_named_route_methods(mod, name) + mod.send :undef_method, :"#{name}_path" + mod.send :undef_method, :"#{name}_url" + end end # :stopdoc: |