提交 0088b08d 编写于 作者: A Aaron Patterson

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.
上级 41931b8a
...@@ -90,7 +90,7 @@ class NamedRouteCollection #:nodoc: ...@@ -90,7 +90,7 @@ class NamedRouteCollection #:nodoc:
def initialize def initialize
@routes = {} @routes = {}
@helpers = [] @helpers = Set.new
@module = Module.new @module = Module.new
end end
...@@ -100,7 +100,7 @@ def helper_names ...@@ -100,7 +100,7 @@ def helper_names
def clear! def clear!
@helpers.each do |helper| @helpers.each do |helper|
@module.remove_possible_method helper @module.send :undef_method, helper
end end
@routes.clear @routes.clear
...@@ -108,7 +108,11 @@ def clear! ...@@ -108,7 +108,11 @@ def clear!
end end
def add(name, route) 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) define_named_route_methods(@module, name, route)
end end
...@@ -256,7 +260,6 @@ def handle_positional_args(controller_options, inner_options, args, result, path ...@@ -256,7 +260,6 @@ def handle_positional_args(controller_options, inner_options, args, result, path
def define_url_helper(mod, route, name, opts, route_key, url_strategy) def define_url_helper(mod, route, name, opts, route_key, url_strategy)
helper = UrlHelper.create(route, opts, route_key, url_strategy) helper = UrlHelper.create(route, opts, route_key, url_strategy)
mod.remove_possible_method name
mod.module_eval do mod.module_eval do
define_method(name) do |*args| define_method(name) do |*args|
options = nil options = nil
...@@ -272,6 +275,11 @@ def define_named_route_methods(mod, name, route) ...@@ -272,6 +275,11 @@ def define_named_route_methods(mod, name, route)
define_url_helper mod, route, :"#{name}_path", route.defaults, name, PATH define_url_helper mod, route, :"#{name}_path", route.defaults, name, PATH
define_url_helper mod, route, :"#{name}_url", route.defaults, name, FULL define_url_helper mod, route, :"#{name}_url", route.defaults, name, FULL
end end
def undef_named_route_methods(mod, name)
mod.send :undef_method, :"#{name}_path"
mod.send :undef_method, :"#{name}_url"
end
end end
# :stopdoc: # :stopdoc:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册