From 7de994fa215e9f4c2856d85034bc4dd7b65d0c01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Strza=C5=82kowski?= Date: Wed, 28 Aug 2013 23:43:33 +0200 Subject: Port all remaining self.protected_instance_variables to class methods --- actionmailer/lib/action_mailer/base.rb | 6 ++++-- 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 +- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index ada86fbc4f..9dcd4bf554 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -373,8 +373,6 @@ module ActionMailer include AbstractController::AssetPaths include AbstractController::Callbacks - self.protected_instance_variables = [:@_action_has_layout] - helper ActionMailer::MailHelper private_class_method :new #:nodoc: @@ -387,6 +385,10 @@ module ActionMailer parts_order: [ "text/plain", "text/enriched", "text/html" ] }.freeze + def self.default_protected_instance_vars + super.concat [:@_action_has_layout] + end + class << self # Register one or more Observers which will be notified when mail is delivered. def register_observers(*observers) diff --git a/actionpack/lib/abstract_controller/base.rb b/actionpack/lib/abstract_controller/base.rb index af5de815bb..a84ed17bd4 100644 --- a/actionpack/lib/abstract_controller/base.rb +++ b/actionpack/lib/abstract_controller/base.rb @@ -114,6 +114,11 @@ 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 5a5c47eb3b..41f19fba78 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -13,13 +13,8 @@ module AbstractController module Rendering extend ActiveSupport::Concern - included do - class_attribute :protected_instance_variables - self.protected_instance_variables = [] - end - - def default_protected_instance_vars - [:@_action_name, :@_response_body, :@_formats, :@_prefixes, :@_config] + def self.default_protected_instance_vars + super.concat [:@_action_name, :@_response_body, :@_formats, :@_prefixes, :@_config] end # Raw rendering of a template to a string. @@ -57,10 +52,9 @@ module AbstractController # :api: public def view_assigns hash = {} - variables = instance_variables - variables -= protected_instance_variables - variables -= default_protected_instance_vars - variables.each { |name| hash[name[1..-1]] = instance_variable_get(name) } + (instance_variables - self.class.default_protected_instance_vars).each do |name| + hash[name[1..-1]] = instance_variable_get(name) + end hash end diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 9941c06201..a00eafc9ed 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -261,11 +261,12 @@ module ActionController include mod 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 - ] + def self.default_protected_instance_vars + super.concat [ + :@_status, :@_headers, :@_params, :@_env, :@_response, :@_request, + :@_view_runtime, :@_stream, :@_url_options, :@_action_has_layout + ] + end 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 3b5d7ef446..e58a1aadb8 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.protected_instance_variables.include?(ivar) + next if ActionController::Base.default_protected_instance_vars.include?(ivar) assigns[ivar[1..-1]] = instance_variable_get(ivar) end -- cgit v1.2.3