aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <tenderlove@github.com>2019-02-22 23:00:30 -0800
committerGitHub <noreply@github.com>2019-02-22 23:00:30 -0800
commitbe442ccd8342baf39e73b01a6fdd38e1a3b15c2c (patch)
tree493c96e9836fa06ea7fa1eae5b358088e05c02c6
parentf3641b187e93808ceadd1e0d4b45ad7a484be4d9 (diff)
parent52eafbd7495367aa48192100a922181d097e5b22 (diff)
downloadrails-be442ccd8342baf39e73b01a6fdd38e1a3b15c2c.tar.gz
rails-be442ccd8342baf39e73b01a6fdd38e1a3b15c2c.tar.bz2
rails-be442ccd8342baf39e73b01a6fdd38e1a3b15c2c.zip
Merge pull request #35374 from rails/cache-inline-templates
Add a finalizer to inline templates
-rw-r--r--actionview/lib/action_view/renderer/template_renderer.rb2
-rw-r--r--actionview/lib/action_view/template.rb1
-rw-r--r--actionview/lib/action_view/template/inline.rb22
3 files changed, 24 insertions, 1 deletions
diff --git a/actionview/lib/action_view/renderer/template_renderer.rb b/actionview/lib/action_view/renderer/template_renderer.rb
index a129ef0e15..87f6cf3de3 100644
--- a/actionview/lib/action_view/renderer/template_renderer.rb
+++ b/actionview/lib/action_view/renderer/template_renderer.rb
@@ -34,7 +34,7 @@ module ActionView
else
@lookup_context.formats.first
end
- Template.new(options[:inline], "inline template", handler, locals: keys, format: format)
+ Template::Inline.new(options[:inline], "inline template", handler, locals: keys, format: format)
elsif options.key?(:template)
if options[:template].respond_to?(:render)
options[:template]
diff --git a/actionview/lib/action_view/template.rb b/actionview/lib/action_view/template.rb
index 907b322c8a..133a316405 100644
--- a/actionview/lib/action_view/template.rb
+++ b/actionview/lib/action_view/template.rb
@@ -115,6 +115,7 @@ module ActionView
autoload :Error
autoload :Handlers
autoload :HTML
+ autoload :Inline
autoload :Text
autoload :Types
end
diff --git a/actionview/lib/action_view/template/inline.rb b/actionview/lib/action_view/template/inline.rb
new file mode 100644
index 0000000000..44658487ea
--- /dev/null
+++ b/actionview/lib/action_view/template/inline.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+module ActionView #:nodoc:
+ class Template #:nodoc:
+ class Inline < Template #:nodoc:
+ # This finalizer is needed (and exactly with a proc inside another proc)
+ # otherwise templates leak in development.
+ Finalizer = proc do |method_name, mod| # :nodoc:
+ proc do
+ mod.module_eval do
+ remove_possible_method method_name
+ end
+ end
+ end
+
+ def compile(mod)
+ super
+ ObjectSpace.define_finalizer(self, Finalizer[method_name, mod])
+ end
+ end
+ end
+end