Skip to content

Commit

Permalink
Merge pull request #12110 from strzalek/revert-default-protected-inst…
Browse files Browse the repository at this point in the history
…ance-vars

Revert default protected instance vars
  • Loading branch information
rafaelfranca committed Sep 2, 2013
2 parents 90ea6f9 + 544d0fa commit e3b6953
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 25 deletions.
6 changes: 2 additions & 4 deletions actionmailer/lib/action_mailer/base.rb
Expand Up @@ -373,6 +373,8 @@ class Base < AbstractController::Base
include AbstractController::AssetPaths
include AbstractController::Callbacks

self.protected_instance_variables = [:@_action_has_layout]

helper ActionMailer::MailHelper

private_class_method :new #:nodoc:
Expand All @@ -385,10 +387,6 @@ class Base < AbstractController::Base
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)
Expand Down
5 changes: 0 additions & 5 deletions actionpack/lib/abstract_controller/base.rb
Expand Up @@ -114,11 +114,6 @@ def method_added(name)
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.
Expand Down
17 changes: 12 additions & 5 deletions actionpack/lib/abstract_controller/rendering.rb
Expand Up @@ -13,8 +13,9 @@ def initialize(message = nil)
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

# Raw rendering of a template to a string.
Expand Down Expand Up @@ -47,14 +48,20 @@ def render(*args, &block)
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
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_VARIABLES
variables.each { |name| hash[name[1..-1]] = instance_variable_get(name) }
hash
end

Expand Down
11 changes: 5 additions & 6 deletions actionpack/lib/action_controller/base.rb
Expand Up @@ -261,12 +261,11 @@ def self.without_modules(*modules)
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
Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/controller/filters_test.rb
Expand Up @@ -17,7 +17,7 @@ def before_filters
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

Expand Down
4 changes: 0 additions & 4 deletions actionview/lib/action_view/rendering.rb
Expand Up @@ -109,10 +109,6 @@ def rendered_format
Mime[lookup_context.rendered_format]
end

def default_protected_instance_vars
super.concat([:@_view_context_class, :@_view_renderer, :@_lookup_context])
end

private

# Normalize args and options.
Expand Down

0 comments on commit e3b6953

Please sign in to comment.