aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view/lookup_context.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2019-01-28 14:03:40 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2019-01-28 14:03:40 -0800
commit4ceaf55aea720036356f9e71540449924eef958d (patch)
treeff2e97db66e3abf7684ae48447e92997ec27cfa0 /actionview/lib/action_view/lookup_context.rb
parent8f8d8b3c19b88d3f51f83872328847f45fc78de4 (diff)
downloadrails-4ceaf55aea720036356f9e71540449924eef958d.tar.gz
rails-4ceaf55aea720036356f9e71540449924eef958d.tar.bz2
rails-4ceaf55aea720036356f9e71540449924eef958d.zip
Deprecate `with_fallbacks` using a block
This patch changes `with_fallbacks` to be a factory method that returns a new instance of a lookup context which contains the fallback view paths in addition to the controller specific view paths. Since the lookup context is more "read only", we may be able to cache them
Diffstat (limited to 'actionview/lib/action_view/lookup_context.rb')
-rw-r--r--actionview/lib/action_view/lookup_context.rb24
1 files changed, 19 insertions, 5 deletions
diff --git a/actionview/lib/action_view/lookup_context.rb b/actionview/lib/action_view/lookup_context.rb
index cc262dc2b7..c2f6439e26 100644
--- a/actionview/lib/action_view/lookup_context.rb
+++ b/actionview/lib/action_view/lookup_context.rb
@@ -3,6 +3,7 @@
require "concurrent/map"
require "active_support/core_ext/module/remove_method"
require "active_support/core_ext/module/attribute_accessors"
+require "active_support/deprecation"
require "action_view/template/resolver"
module ActionView
@@ -132,11 +133,24 @@ module ActionView
# Adds fallbacks to the view paths. Useful in cases when you are rendering
# a :file.
def with_fallbacks
- view_paths = @view_paths
- @view_paths = build_view_paths((view_paths.paths + self.class.fallbacks).uniq)
- yield
- ensure
- @view_paths = view_paths
+ view_paths = build_view_paths((@view_paths.paths + self.class.fallbacks).uniq)
+
+ if block_given?
+ ActiveSupport::Deprecation.warn <<~eowarn
+ Calling `with_fallbacks` with a block is deprecated. Call methods on
+ the lookup context returned by `with_fallbacks` instead.
+ eowarn
+
+ begin
+ _view_paths = @view_paths
+ @view_paths = view_paths
+ yield
+ ensure
+ @view_paths = _view_paths
+ end
+ else
+ ActionView::LookupContext.new(view_paths, @details, @prefixes)
+ end
end
private