1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Only cache the view_context_class in one place

This patch removes the instance writer of view_context_class.
Subclasses may override it, but it doesn't need to be written.  This
also eliminates the need to cache the return value of the class level
`view_context_class` method.
This commit is contained in:
Aaron Patterson 2019-01-18 15:07:22 -08:00
parent 63d96adb68
commit 8611b15924
No known key found for this signature in database
GPG key ID: 953170BCB4FFAFC6
2 changed files with 9 additions and 4 deletions

View file

@ -160,9 +160,16 @@ module ActionDispatch
@controller.singleton_class.include(_routes.url_helpers)
if @controller.respond_to? :view_context_class
@controller.view_context_class = Class.new(@controller.view_context_class) do
view_context_class = Class.new(@controller.view_context_class) do
include _routes.url_helpers
end
custom_view_context = Module.new {
define_method(:view_context_class) do
view_context_class
end
}
@controller.extend(custom_view_context)
end
end
yield @routes

View file

@ -55,10 +55,8 @@ module ActionView
end
end
attr_internal_writer :view_context_class
def view_context_class
@_view_context_class ||= self.class.view_context_class
self.class.view_context_class
end
# An instance of a view class. The default view class is ActionView::Base.