diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-07-30 14:46:07 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-07-30 14:46:07 -0700 |
commit | 210b338db20b1cdd0684f40bd78b52ed16148b99 (patch) | |
tree | ae1a1e6c050686697149d7eeac5e107d58875c46 /actionpack | |
parent | cf6658c2842d92c7d23928ec6f72074dce345f15 (diff) | |
download | rails-210b338db20b1cdd0684f40bd78b52ed16148b99.tar.gz rails-210b338db20b1cdd0684f40bd78b52ed16148b99.tar.bz2 rails-210b338db20b1cdd0684f40bd78b52ed16148b99.zip |
split path_helpers and url_helpers
this lets us avoid hard coding a regexp for separating path and url
helpers in the clear! method.
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/route_set.rb | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 459097f327..42d6ee40db 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -86,45 +86,54 @@ module ActionDispatch # named routes. class NamedRouteCollection #:nodoc: include Enumerable - attr_reader :routes, :helpers, :url_helpers_module + attr_reader :routes, :url_helpers_module def initialize @routes = {} - @helpers = Set.new + @path_helpers = Set.new + @url_helpers = Set.new @url_helpers_module = Module.new @path_helpers_module = Module.new end def route_defined?(name) - @helpers.include? name.to_sym + key = name.to_sym + @path_helpers.include?(key) || @url_helpers.include?(key) end def helper_names - @helpers.map(&:to_s) + @path_helpers.map(&:to_s) + @url_helpers.map(&:to_s) end def clear! - @helpers.each do |helper| - if helper =~ /_path$/ - @path_helpers_module.send :undef_method, helper - else - @url_helpers_module.send :undef_method, helper - end + @path_helpers.each do |helper| + @path_helpers_module.send :undef_method, helper + end + + @url_helpers.each do |helper| + @url_helpers_module.send :undef_method, helper end @routes.clear - @helpers.clear + @path_helpers.clear + @url_helpers.clear end def add(name, route) - key = name.to_sym + key = name.to_sym + path_name = :"#{name}_path" + url_name = :"#{name}_url" + if routes.key? key - @path_helpers_module.send :undef_method, :"#{name}_path" - @url_helpers_module.send :undef_method, :"#{name}_url" + @path_helpers_module.send :undef_method, path_name + @url_helpers_module.send :undef_method, url_name end routes[key] = route - define_url_helper @path_helpers_module, route, :"#{name}_path", route.defaults, name, PATH - define_url_helper @url_helpers_module, route, :"#{name}_url", route.defaults, name, FULL + define_url_helper @path_helpers_module, route, path_name, route.defaults, name, PATH + define_url_helper @url_helpers_module, route, url_name, route.defaults, name, FULL + + @path_helpers << path_name + @url_helpers << url_name end def get(name) @@ -297,8 +306,6 @@ module ActionDispatch helper.call self, args, options end end - - helpers << name end end |