aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2015-02-01 22:50:41 +0000
committerAndrew White <andyw@pixeltrix.co.uk>2015-02-01 22:50:41 +0000
commit226cd8a094c81edb72143173e4d0c88a2eb01d5f (patch)
tree92b5f20bd4d1e762d35574e0c29fc9ec8b0bb188 /actionpack/lib
parentf2f4ed2159865445f4cf05cb778dedf48368ec4d (diff)
downloadrails-226cd8a094c81edb72143173e4d0c88a2eb01d5f.tar.gz
rails-226cd8a094c81edb72143173e4d0c88a2eb01d5f.tar.bz2
rails-226cd8a094c81edb72143173e4d0c88a2eb01d5f.zip
Cache `url_helpers` separately for mailers
The commit 3b63780 re-introduced url helper caching but we need to cache a separate module for Action Mailer without paths.
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb94
1 files changed, 50 insertions, 44 deletions
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index 3dee42a0f0..f45449c371 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -410,63 +410,69 @@ module ActionDispatch
end
def url_helpers(supports_path = true)
- @url_helpers ||= begin
- routes = self
-
- Module.new do
- extend ActiveSupport::Concern
- include UrlFor
-
- # Define url_for in the singleton level so one can do:
- # Rails.application.routes.url_helpers.url_for(args)
- @_routes = routes
- class << self
- def url_for(options)
- @_routes.url_for(options)
- end
+ if supports_path
+ @url_helpers_with_paths ||= generate_url_helpers(supports_path)
+ else
+ @url_helpers_without_paths ||= generate_url_helpers(supports_path)
+ end
+ end
- def optimize_routes_generation?
- @_routes.optimize_routes_generation?
- end
+ def generate_url_helpers(supports_path)
+ routes = self
+
+ Module.new do
+ extend ActiveSupport::Concern
+ include UrlFor
+
+ # Define url_for in the singleton level so one can do:
+ # Rails.application.routes.url_helpers.url_for(args)
+ @_routes = routes
+ class << self
+ def url_for(options)
+ @_routes.url_for(options)
+ end
- attr_reader :_routes
- def url_options; {}; end
+ def optimize_routes_generation?
+ @_routes.optimize_routes_generation?
end
- url_helpers = routes.named_routes.url_helpers_module
+ attr_reader :_routes
+ def url_options; {}; end
+ end
- # Make named_routes available in the module singleton
- # as well, so one can do:
- # Rails.application.routes.url_helpers.posts_path
- extend url_helpers
+ url_helpers = routes.named_routes.url_helpers_module
- # Any class that includes this module will get all
- # named routes...
- include url_helpers
+ # Make named_routes available in the module singleton
+ # as well, so one can do:
+ # Rails.application.routes.url_helpers.posts_path
+ extend url_helpers
- if supports_path
- path_helpers = routes.named_routes.path_helpers_module
+ # Any class that includes this module will get all
+ # named routes...
+ include url_helpers
- include path_helpers
- extend path_helpers
- end
+ if supports_path
+ path_helpers = routes.named_routes.path_helpers_module
- # plus a singleton class method called _routes ...
- included do
- singleton_class.send(:redefine_method, :_routes) { routes }
- end
+ include path_helpers
+ extend path_helpers
+ end
- # And an instance method _routes. Note that
- # UrlFor (included in this module) add extra
- # conveniences for working with @_routes.
- define_method(:_routes) { @_routes || routes }
+ # plus a singleton class method called _routes ...
+ included do
+ singleton_class.send(:redefine_method, :_routes) { routes }
+ end
- define_method(:_generate_paths_by_default) do
- supports_path
- end
+ # And an instance method _routes. Note that
+ # UrlFor (included in this module) add extra
+ # conveniences for working with @_routes.
+ define_method(:_routes) { @_routes || routes }
- private :_generate_paths_by_default
+ define_method(:_generate_paths_by_default) do
+ supports_path
end
+
+ private :_generate_paths_by_default
end
end