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.
This commit is contained in:
Andrew White 2015-02-01 22:50:41 +00:00
parent f2f4ed2159
commit 226cd8a094

@ -410,63 +410,69 @@ def #{name}
end
def url_helpers(supports_path = true)
@url_helpers ||= begin
routes = self
if supports_path
@url_helpers_with_paths ||= generate_url_helpers(supports_path)
else
@url_helpers_without_paths ||= generate_url_helpers(supports_path)
end
end
Module.new do
extend ActiveSupport::Concern
include UrlFor
def generate_url_helpers(supports_path)
routes = self
# 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
Module.new do
extend ActiveSupport::Concern
include UrlFor
def optimize_routes_generation?
@_routes.optimize_routes_generation?
end
attr_reader :_routes
def url_options; {}; end
# 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
url_helpers = routes.named_routes.url_helpers_module
# Make named_routes available in the module singleton
# as well, so one can do:
# Rails.application.routes.url_helpers.posts_path
extend url_helpers
# Any class that includes this module will get all
# named routes...
include url_helpers
if supports_path
path_helpers = routes.named_routes.path_helpers_module
include path_helpers
extend path_helpers
def optimize_routes_generation?
@_routes.optimize_routes_generation?
end
# plus a singleton class method called _routes ...
included do
singleton_class.send(:redefine_method, :_routes) { routes }
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 }
define_method(:_generate_paths_by_default) do
supports_path
end
private :_generate_paths_by_default
attr_reader :_routes
def url_options; {}; end
end
url_helpers = routes.named_routes.url_helpers_module
# Make named_routes available in the module singleton
# as well, so one can do:
# Rails.application.routes.url_helpers.posts_path
extend url_helpers
# Any class that includes this module will get all
# named routes...
include url_helpers
if supports_path
path_helpers = routes.named_routes.path_helpers_module
include path_helpers
extend path_helpers
end
# plus a singleton class method called _routes ...
included do
singleton_class.send(:redefine_method, :_routes) { routes }
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 }
define_method(:_generate_paths_by_default) do
supports_path
end
private :_generate_paths_by_default
end
end