aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-06-10 19:39:09 +0200
committerJosé Valim <jose.valim@gmail.com>2010-06-10 19:39:09 +0200
commitb67ec8ba20099c8b39bf344f385bbbd2b9c8f47d (patch)
tree008a576bb72baffd49b2483b3b08e181933e29c1 /actionpack
parentc4d6245e875bbb276c122a5a401422d341dac4df (diff)
downloadrails-b67ec8ba20099c8b39bf344f385bbbd2b9c8f47d.tar.gz
rails-b67ec8ba20099c8b39bf344f385bbbd2b9c8f47d.tar.bz2
rails-b67ec8ba20099c8b39bf344f385bbbd2b9c8f47d.zip
class_attribute is not a direct replacement of class_inheritable_*.
If you are setting a hash or an array in class_attribute or you need to freeze it, to ensure people won't modify it in place or you need to dup it on inheritance.
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/abstract_controller/view_paths.rb3
-rw-r--r--actionpack/lib/action_controller/metal/hide_actions.rb6
-rw-r--r--actionpack/lib/action_view/base.rb17
3 files changed, 12 insertions, 14 deletions
diff --git a/actionpack/lib/abstract_controller/view_paths.rb b/actionpack/lib/abstract_controller/view_paths.rb
index b331eb51b6..b552a649d1 100644
--- a/actionpack/lib/abstract_controller/view_paths.rb
+++ b/actionpack/lib/abstract_controller/view_paths.rb
@@ -5,6 +5,7 @@ module AbstractController
included do
class_attribute :_view_paths
self._view_paths = ActionView::PathSet.new
+ self._view_paths.freeze
end
delegate :find_template, :template_exists?, :view_paths, :formats, :formats=,
@@ -61,7 +62,7 @@ module AbstractController
# paths<ViewPathSet, Object>:: If a ViewPathSet is provided, use that;
# otherwise, process the parameter into a ViewPathSet.
def view_paths=(paths)
- self._view_paths = paths.is_a?(ActionView::PathSet) ? paths : ActionView::Base.process_view_paths(paths)
+ self._view_paths = ActionView::Base.process_view_paths(paths)
self._view_paths.freeze
end
end
diff --git a/actionpack/lib/action_controller/metal/hide_actions.rb b/actionpack/lib/action_controller/metal/hide_actions.rb
index 3358d80c35..32d7a96701 100644
--- a/actionpack/lib/action_controller/metal/hide_actions.rb
+++ b/actionpack/lib/action_controller/metal/hide_actions.rb
@@ -8,7 +8,7 @@ module ActionController
included do
class_attribute :hidden_actions
- self.hidden_actions = Set.new
+ self.hidden_actions = Set.new.freeze
end
private
@@ -25,7 +25,7 @@ module ActionController
# ==== Parameters
# *args<#to_s>:: A list of actions
def hide_action(*args)
- self.hidden_actions = hidden_actions.dup.merge(args.map(&:to_s))
+ self.hidden_actions = hidden_actions.dup.merge(args.map(&:to_s)).freeze
end
def inherited(klass)
@@ -41,7 +41,7 @@ module ActionController
# Overrides AbstractController::Base#action_methods to remove any methods
# that are listed as hidden methods.
def action_methods
- @action_methods ||= Set.new(super.reject {|name| hidden_actions.include?(name)})
+ @action_methods ||= Set.new(super.reject { |name| hidden_actions.include?(name) })
end
end
end
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index 7dd9dea358..2efc575081 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -158,7 +158,6 @@ module ActionView #:nodoc:
end
include Helpers, Rendering, Partials, Layouts, ::ERB::Util, Context
- extend ActiveSupport::Memoizable
# Specify whether RJS responses should be wrapped in a try/catch block
# that alert()s the caught exception (and then re-raises it).
@@ -170,9 +169,6 @@ module ActionView #:nodoc:
@@field_error_proc = Proc.new{ |html_tag, instance| "<div class=\"field_with_errors\">#{html_tag}</div>".html_safe }
class_attribute :helpers
- remove_method :helpers
- attr_reader :helpers
-
class_attribute :_router
class << self
@@ -201,20 +197,21 @@ module ActionView #:nodoc:
end
def self.process_view_paths(value)
- return value.dup if value.is_a?(PathSet)
- ActionView::PathSet.new(Array.wrap(value))
+ value.is_a?(PathSet) ?
+ value.dup : ActionView::PathSet.new(Array.wrap(value))
end
def initialize(lookup_context = nil, assigns_for_first_render = {}, controller = nil, formats = nil) #:nodoc:
- @config = nil
- @assigns = assigns_for_first_render.each { |key, value| instance_variable_set("@#{key}", value) }
- @helpers = self.class.helpers || Module.new
+ self.assigns = assigns_for_first_render.each { |key, value| instance_variable_set("@#{key}", value) }
+ self.helpers = self.class.helpers || Module.new
if @_controller = controller
@_request = controller.request if controller.respond_to?(:request)
end
- @_config = ActiveSupport::InheritableOptions.new(controller.config) if controller && controller.respond_to?(:config)
+ config = controller && controller.respond_to?(:config) ? controller.config : {}
+ @_config = ActiveSupport::InheritableOptions.new(config)
+
@_content_for = Hash.new { |h,k| h[k] = ActiveSupport::SafeBuffer.new }
@_virtual_path = nil
@output_buffer = nil