From 40fcb9e82220fe9a7a3b0b3aeee61f92f00942c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Strza=C5=82kowski?= Date: Mon, 2 Sep 2013 23:05:42 +0200 Subject: Revert "Port all remaining self.protected_instance_variables to class methods" This reverts commit 7de994fa215e9f4c2856d85034bc4dd7b65d0c01. --- actionpack/lib/abstract_controller/base.rb | 5 ----- actionpack/lib/abstract_controller/rendering.rb | 16 +++++++++++----- actionpack/lib/action_controller/base.rb | 11 +++++------ actionpack/test/controller/filters_test.rb | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/abstract_controller/base.rb b/actionpack/lib/abstract_controller/base.rb index a84ed17bd4..af5de815bb 100644 --- a/actionpack/lib/abstract_controller/base.rb +++ b/actionpack/lib/abstract_controller/base.rb @@ -114,11 +114,6 @@ module AbstractController end end - # Define some internal variables that should not be propagated to the view. - def self.default_protected_instance_vars - [] - end - abstract! # Calls the action going through the entire action dispatch stack. diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 41f19fba78..5a5c47eb3b 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -13,8 +13,13 @@ module AbstractController module Rendering extend ActiveSupport::Concern - def self.default_protected_instance_vars - super.concat [:@_action_name, :@_response_body, :@_formats, :@_prefixes, :@_config] + included do + class_attribute :protected_instance_variables + self.protected_instance_variables = [] + end + + def default_protected_instance_vars + [:@_action_name, :@_response_body, :@_formats, :@_prefixes, :@_config] end # Raw rendering of a template to a string. @@ -52,9 +57,10 @@ module AbstractController # :api: public def view_assigns hash = {} - (instance_variables - self.class.default_protected_instance_vars).each do |name| - hash[name[1..-1]] = instance_variable_get(name) - end + variables = instance_variables + variables -= protected_instance_variables + variables -= default_protected_instance_vars + variables.each { |name| hash[name[1..-1]] = instance_variable_get(name) } hash end diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index a00eafc9ed..9941c06201 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -261,12 +261,11 @@ module ActionController include mod end - def self.default_protected_instance_vars - super.concat [ - :@_status, :@_headers, :@_params, :@_env, :@_response, :@_request, - :@_view_runtime, :@_stream, :@_url_options, :@_action_has_layout - ] - end + # Define some internal variables that should not be propagated to the view. + self.protected_instance_variables = [ + :@_status, :@_headers, :@_params, :@_env, :@_response, :@_request, + :@_view_runtime, :@_stream, :@_url_options, :@_action_has_layout + ] ActiveSupport.run_load_hooks(:action_controller, self) end diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index e58a1aadb8..3b5d7ef446 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -17,7 +17,7 @@ class ActionController::Base def assigns(key = nil) assigns = {} instance_variables.each do |ivar| - next if ActionController::Base.default_protected_instance_vars.include?(ivar) + next if ActionController::Base.protected_instance_variables.include?(ivar) assigns[ivar[1..-1]] = instance_variable_get(ivar) end -- cgit v1.2.3 From 544d0fad3d76bd3077225c6afcb562197f240cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Strza=C5=82kowski?= Date: Mon, 2 Sep 2013 23:06:14 +0200 Subject: Return to using protected_instance_variables in AV --- actionpack/lib/abstract_controller/rendering.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 5a5c47eb3b..a3c45bacb7 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -18,10 +18,6 @@ module AbstractController self.protected_instance_variables = [] end - def default_protected_instance_vars - [:@_action_name, :@_response_body, :@_formats, :@_prefixes, :@_config] - end - # Raw rendering of a template to a string. # # It is similar to render, except that it does not @@ -52,6 +48,11 @@ module AbstractController def rendered_format end + DEFAULT_PROTECTED_INSTANCE_VARIABLES = %w( + @_action_name @_response_body @_formats @_prefixes @_config + @_view_context_class @_view_renderer @_lookup_context + ) + # This method should return a hash with assigns. # You can overwrite this configuration per controller. # :api: public @@ -59,7 +60,7 @@ module AbstractController hash = {} variables = instance_variables variables -= protected_instance_variables - variables -= default_protected_instance_vars + variables -= DEFAULT_PROTECTED_INSTANCE_VARIABLES variables.each { |name| hash[name[1..-1]] = instance_variable_get(name) } hash end -- cgit v1.2.3