Permalink
Browse files

Merge branch 'master' of git@github.com:rails/rails

  • Loading branch information...
2 parents 32b82e4 + 1d18651 commit 6ef4239f8bd4d4ea7a5bc7f2cdaf14f87e6eb9a1 @gbuesing gbuesing committed Apr 21, 2008
View
@@ -1,5 +1,7 @@
*SVN*
+* Remove ActionController::Base#view_controller_internals flag. [Pratik]
+
* Add conditional options to caches_page method. [Paul Horsfall]
* Move missing template logic to ActionView. [Pratik]
@@ -253,16 +253,11 @@ class Base
DEFAULT_RENDER_STATUS_CODE = "200 OK"
include StatusCodes
-
- # Determines whether the view has access to controller internals @request, @response, @session, and @template.
- # By default, it does.
- @@view_controller_internals = true
- cattr_accessor :view_controller_internals
-
- # Protected instance variable cache
- @@protected_variables_cache = nil
- cattr_accessor :protected_variables_cache
-
+
+ # Controller specific instance variables which will not be accessible inside views.
+ @@protected_view_variables = %w(@assigns @performed_redirect @performed_render @variables_added @request_origin @url @parent_controller
+ @action_name @before_filter_chain_aborted @action_cache_path)
+
# Prepends all the URL-generating helpers from AssetHelper. This makes it possible to easily move javascripts, stylesheets,
# and images to a dedicated asset server away from the main web server. Example:
# ActionController::Base.asset_host = "http://assets.example.com"
@@ -1194,7 +1189,6 @@ def self.action_methods
def add_variables_to_assigns
unless @variables_added
add_instance_variables_to_assigns
- add_class_variables_to_assigns if view_controller_internals
@variables_added = true
end
end
@@ -1208,30 +1202,11 @@ def reset_variables_added_to_assigns
end
def add_instance_variables_to_assigns
- @@protected_variables_cache ||= Set.new(protected_instance_variables)
- instance_variable_names.each do |var|
- next if @@protected_variables_cache.include?(var)
+ (instance_variable_names - @@protected_view_variables).each do |var|
@assigns[var[1..-1]] = instance_variable_get(var)
end
end
- def add_class_variables_to_assigns
- %w(view_paths logger).each do |cvar|
- @assigns[cvar] = self.send(cvar)
- end
- end
-
- def protected_instance_variables
- if view_controller_internals
- %w(@assigns @performed_redirect @performed_render)
- else
- %w(@assigns @performed_redirect @performed_render
- @_request @request @_response @response @_params @params
- @_session @session @_cookies @cookies
- @template @request_origin @parent_controller)
- end
- end
-
def request_origin
# this *needs* to be cached!
# otherwise you'd get different results if calling it more than once
@@ -41,7 +41,6 @@ def self.included(base) #:nodoc:
base.extend(ClassMethods)
base.class_eval do
attr_accessor :rendered_action_cache, :action_cache_path
- alias_method_chain :protected_instance_variables, :action_caching
end
end
@@ -55,10 +54,6 @@ def caches_action(*actions)
end
protected
- def protected_instance_variables_with_action_caching
- protected_instance_variables_without_action_caching + %w(@action_cache_path)
- end
-
def expire_action(options = {})
return unless cache_configured?
@@ -529,26 +529,10 @@ def test_private_methods
end
def test_access_to_request_in_view
- view_internals_old_value = ActionController::Base.view_controller_internals
-
- ActionController::Base.view_controller_internals = false
- ActionController::Base.protected_variables_cache = nil
-
- get :hello_world
- assert !assigns.include?('_request'), '_request should not be in assigns'
- assert !assigns.include?('request'), 'request should not be in assigns'
-
- ActionController::Base.view_controller_internals = true
- ActionController::Base.protected_variables_cache = nil
-
get :hello_world
assert !assigns.include?('request'), 'request should not be in assigns'
assert_kind_of ActionController::AbstractRequest, assigns['_request']
assert_kind_of ActionController::AbstractRequest, @response.template.request
-
- ensure
- ActionController::Base.view_controller_internals = view_internals_old_value
- ActionController::Base.protected_variables_cache = nil
end
def test_render_xml
@@ -3,17 +3,22 @@ module CoreExtensions #:nodoc:
module DateTime #:nodoc:
# Converting datetimes to formatted strings, dates, and times.
module Conversions
- def self.included(base) #:nodoc:
+ def self.append_features(base) #:nodoc:
base.class_eval do
- alias_method :to_default_s, :to_s if instance_methods.include?(:to_s)
- alias_method :to_s, :to_formatted_s
alias_method :default_inspect, :inspect
- alias_method :inspect, :readable_inspect
+ alias_method :to_default_s, :to_s unless (instance_methods(false) & [:to_s, 'to_s']).empty?
# Ruby 1.9 has DateTime#to_time which internally relies on Time. We define our own #to_time which allows
# DateTimes outside the range of what can be created with Time.
remove_method :to_time if instance_methods.include?(:to_time)
end
+
+ super
+
+ base.class_eval do
+ alias_method :to_s, :to_formatted_s
+ alias_method :inspect, :readable_inspect
+ end
end
# Convert to a formatted string. See Time::DATE_FORMATS for predefined formats.
@@ -1,4 +1,7 @@
module Enumerable
+ # Ruby 1.8.7 introduces group_by, but the result isn't ordered. Override it.
+ remove_method(:group_by) if [].respond_to?(:group_by) && RUBY_VERSION < '1.9'
+
# Collect an enumerable into sets, grouped by the result of a block. Useful,
# for example, for grouping records by date.
#
@@ -19,7 +22,7 @@ def group_by
(grouped[yield(element)] ||= []) << element
grouped
end
- end if RUBY_VERSION < '1.9'
+ end unless [].respond_to?(:group_by)
# Calculates a sum from the elements. Examples:
#
@@ -2,7 +2,7 @@
require 'active_support/core_ext/string/conversions'
require 'active_support/core_ext/string/access'
require 'active_support/core_ext/string/starts_ends_with'
-require 'active_support/core_ext/string/iterators' unless 'test'.respond_to?(:each_char)
+require 'active_support/core_ext/string/iterators'
require 'active_support/core_ext/string/unicode'
require 'active_support/core_ext/string/xchar'
require 'active_support/core_ext/string/filters'
@@ -12,14 +12,7 @@ class String #:nodoc:
include ActiveSupport::CoreExtensions::String::Conversions
include ActiveSupport::CoreExtensions::String::Filters
include ActiveSupport::CoreExtensions::String::Inflections
- if RUBY_VERSION < '1.9'
- include ActiveSupport::CoreExtensions::String::StartsEndsWith
- else
- alias starts_with? start_with?
- alias ends_with? end_with?
- end
- if defined? ActiveSupport::CoreExtensions::String::Iterators
- include ActiveSupport::CoreExtensions::String::Iterators
- end
+ include ActiveSupport::CoreExtensions::String::StartsEndsWith
+ include ActiveSupport::CoreExtensions::String::Iterators
include ActiveSupport::CoreExtensions::String::Unicode
end
@@ -5,6 +5,10 @@ module CoreExtensions #:nodoc:
module String #:nodoc:
# Custom string iterators
module Iterators
+ def self.append_features(base)
+ super unless '1.9'.respond_to?(:each_char)
+ end
+
# Yields a single-character string for each character in the string.
# When $KCODE = 'UTF8', multi-byte characters are yielded appropriately.
def each_char
@@ -3,10 +3,18 @@ module CoreExtensions #:nodoc:
module String #:nodoc:
# Additional string tests.
module StartsEndsWith
- def self.included(base)
- base.class_eval do
- alias_method :start_with?, :starts_with?
- alias_method :end_with?, :ends_with?
+ def self.append_features(base)
+ if '1.8.7 and up'.respond_to?(:start_with?)
+ base.class_eval do
+ alias_method :starts_with?, :start_with?
+ alias_method :ends_with?, :end_with?
+ end
+ else
+ super
+ base.class_eval do
+ alias_method :start_with?, :starts_with?
+ alias_method :end_with?, :ends_with?
+ end
end
end

0 comments on commit 6ef4239

Please sign in to comment.