public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Remove ActionController::Base#view_controller_internals

Get rid of ActionController::Base#view_controller_internals flag and
use @@protected_view_variables for storing the list of controller
specific instance variables which should be inaccessible inside views.
lifo (author)
Sun Apr 20 19:38:16 -0700 2008
commit  2b69840e5efba885c8ec6281d5b8a56fcabff283
tree    6535bda8b27784e097a0fe44cf692e150e3ad2bb
parent  caa03a5c870c6a03a35f6dcfaf040a6d689eaee2
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *SVN*
0
 
0
+* Remove ActionController::Base#view_controller_internals flag. [Pratik]
0
+
0
 * Add conditional options to caches_page method. [Paul Horsfall]
0
 
0
 * Move missing template logic to ActionView. [Pratik]
...
253
254
255
256
257
258
259
260
261
262
263
264
265
 
 
 
 
 
266
267
268
...
1207
1208
1209
1210
1211
1212
 
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
...
253
254
255
 
 
 
 
 
 
 
 
 
 
256
257
258
259
260
261
262
263
...
1202
1203
1204
 
 
 
1205
1206
1207
1208
1209
 
 
 
 
 
 
 
 
 
 
 
1210
1211
1212
0
@@ -253,16 +253,11 @@ module ActionController #:nodoc:
0
     DEFAULT_RENDER_STATUS_CODE = "200 OK"
0
 
0
     include StatusCodes
0
-
0
-    # Determines whether the view has access to controller internals @request, @response, @session, and @template.
0
-    # By default, it does.
0
-    @@view_controller_internals = true
0
-    cattr_accessor :view_controller_internals
0
-
0
-    # Protected instance variable cache
0
-    @@protected_variables_cache = nil
0
-    cattr_accessor :protected_variables_cache
0
-
0
+    
0
+    # Controller specific instance variables which will not be accessible inside views.
0
+    @@protected_view_variables = %w(@assigns @performed_redirect @performed_render @variables_added @request_origin @url @parent_controller
0
+                                    @action_name @before_filter_chain_aborted @action_cache_path)
0
+    
0
     # Prepends all the URL-generating helpers from AssetHelper. This makes it possible to easily move javascripts, stylesheets,
0
     # and images to a dedicated asset server away from the main web server. Example:
0
     #   ActionController::Base.asset_host = "http://assets.example.com"
0
@@ -1207,24 +1202,11 @@ module ActionController #:nodoc:
0
       end
0
 
0
       def add_instance_variables_to_assigns
0
-        @@protected_variables_cache ||= Set.new(protected_instance_variables)
0
-        instance_variable_names.each do |var|
0
-          next if @@protected_variables_cache.include?(var)
0
+        (instance_variable_names - @@protected_view_variables).each do |var|
0
           @assigns[var[1..-1]] = instance_variable_get(var)
0
         end
0
       end
0
 
0
-      def protected_instance_variables
0
-        if view_controller_internals
0
-          %w(@assigns @performed_redirect @performed_render)
0
-        else
0
-          %w(@assigns @performed_redirect @performed_render
0
-             @_request @request @_response @response @_params @params
0
-             @_session @session @_cookies @cookies
0
-             @template @request_origin @parent_controller)
0
-        end
0
-      end
0
-
0
       def request_origin
0
         # this *needs* to be cached!
0
         # otherwise you'd get different results if calling it more than once
...
41
42
43
44
45
46
47
...
55
56
57
58
59
60
61
62
63
64
...
41
42
43
 
44
45
46
...
54
55
56
 
 
 
 
57
58
59
0
@@ -41,7 +41,6 @@ module ActionController #:nodoc:
0
         base.extend(ClassMethods)
0
           base.class_eval do
0
             attr_accessor :rendered_action_cache, :action_cache_path
0
-            alias_method_chain :protected_instance_variables, :action_caching
0
           end
0
       end
0
 
0
@@ -55,10 +54,6 @@ module ActionController #:nodoc:
0
       end
0
 
0
       protected
0
-        def protected_instance_variables_with_action_caching
0
-          protected_instance_variables_without_action_caching + %w(@action_cache_path)
0
-        end
0
-
0
         def expire_action(options = {})
0
           return unless cache_configured?
0
 
...
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
...
529
530
531
 
 
 
 
 
 
 
 
 
 
 
 
532
533
534
535
 
 
 
 
536
537
538
0
@@ -529,26 +529,10 @@ class NewRenderTest < Test::Unit::TestCase
0
   end
0
 
0
   def test_access_to_request_in_view
0
-    view_internals_old_value = ActionController::Base.view_controller_internals
0
-
0
-    ActionController::Base.view_controller_internals = false
0
-    ActionController::Base.protected_variables_cache = nil
0
-
0
-    get :hello_world
0
-    assert !assigns.include?('_request'), '_request should not be in assigns'
0
-    assert !assigns.include?('request'), 'request should not be in assigns'
0
-
0
-    ActionController::Base.view_controller_internals = true
0
-    ActionController::Base.protected_variables_cache = nil
0
-
0
     get :hello_world
0
     assert !assigns.include?('request'), 'request should not be in assigns'
0
     assert_kind_of ActionController::AbstractRequest, assigns['_request']
0
     assert_kind_of ActionController::AbstractRequest, @response.template.request
0
-
0
-  ensure
0
-    ActionController::Base.view_controller_internals = view_internals_old_value
0
-    ActionController::Base.protected_variables_cache = nil
0
   end
0
 
0
   def test_render_xml

Comments