From f30ca75b3fb673968b6af23b3aadf807aec79ef4 Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Wed, 4 Jun 2008 23:34:27 +0000 Subject: [PATCH] ActionItem392: importing ruby1.8.7 compat changes --- vendor/rails/actionpack/lib/action_controller/cgi_ext/cookie.rb | 8 +++++++- vendor/rails/activesupport/lib/active_support/core_ext/date_time/conversions.rb | 9 ++++++++- vendor/rails/activesupport/lib/active_support/core_ext/enumerable.rb | 5 ++++- vendor/rails/activesupport/lib/active_support/core_ext/string.rb | 13 +++---------- vendor/rails/activesupport/lib/active_support/core_ext/string/iterators.rb | 4 ++++ vendor/rails/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb | 16 ++++++++++++---- vendor/rails/activesupport/lib/active_support/core_ext/string/unicode.rb | 2 ++ vendor/rails/activesupport/lib/active_support/core_ext/symbol.rb | 9 ++++++++- vendor/rails/activesupport/lib/active_support/multibyte/chars.rb | 12 +++++++----- 9 files changed, 55 insertions(+), 23 deletions(-) diff --git a/vendor/rails/actionpack/lib/action_controller/cgi_ext/cookie.rb b/vendor/rails/actionpack/lib/action_controller/cgi_ext/cookie.rb index 07d2f08..06f40c2 100644 --- a/vendor/rails/actionpack/lib/action_controller/cgi_ext/cookie.rb +++ b/vendor/rails/actionpack/lib/action_controller/cgi_ext/cookie.rb @@ -79,7 +79,13 @@ class CGI #:nodoc: buf end - # Parse a raw cookie string into a hash of cookie-name=>Cookie + # FIXME: work around broken 1.8.7 DelegateClass#respond_to? + def respond_to?(method, include_private = false) + return true if super(method) + return __getobj__.respond_to?(method, include_private) + end + + # Parses a raw cookie string into a hash of cookie-name => cookie-object # pairs. # # cookies = CGI::Cookie::parse("raw_cookie_string") diff --git a/vendor/rails/activesupport/lib/active_support/core_ext/date_time/conversions.rb b/vendor/rails/activesupport/lib/active_support/core_ext/date_time/conversions.rb index 8ea8679..2ebaf39 100644 --- a/vendor/rails/activesupport/lib/active_support/core_ext/date_time/conversions.rb +++ b/vendor/rails/activesupport/lib/active_support/core_ext/date_time/conversions.rb @@ -8,12 +8,19 @@ module ActiveSupport #:nodoc: alias_method :to_datetime_default_s, :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 base.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 DATE_FORMATS for predefined formats. diff --git a/vendor/rails/activesupport/lib/active_support/core_ext/enumerable.rb b/vendor/rails/activesupport/lib/active_support/core_ext/enumerable.rb index f35c8f8..c1aa195 100644 --- a/vendor/rails/activesupport/lib/active_support/core_ext/enumerable.rb +++ b/vendor/rails/activesupport/lib/active_support/core_ext/enumerable.rb @@ -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 @@ module Enumerable (groups[yield(element)] ||= []) << element groups end - end if RUBY_VERSION < '1.9' + end unless [].respond_to?(:group_by) # Calculates a sum from the elements. Examples: # diff --git a/vendor/rails/activesupport/lib/active_support/core_ext/string.rb b/vendor/rails/activesupport/lib/active_support/core_ext/string.rb index 5497b6f..c7387cd 100644 --- a/vendor/rails/activesupport/lib/active_support/core_ext/string.rb +++ b/vendor/rails/activesupport/lib/active_support/core_ext/string.rb @@ -2,7 +2,7 @@ require 'active_support/core_ext/string/inflections' 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' @@ -10,14 +10,7 @@ class String #:nodoc: include ActiveSupport::CoreExtensions::String::Access include ActiveSupport::CoreExtensions::String::Conversions 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 diff --git a/vendor/rails/activesupport/lib/active_support/core_ext/string/iterators.rb b/vendor/rails/activesupport/lib/active_support/core_ext/string/iterators.rb index 73114d9..66a08a5 100644 --- a/vendor/rails/activesupport/lib/active_support/core_ext/string/iterators.rb +++ b/vendor/rails/activesupport/lib/active_support/core_ext/string/iterators.rb @@ -5,6 +5,10 @@ module ActiveSupport #: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 diff --git a/vendor/rails/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb b/vendor/rails/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb index 3960669..09f9a18 100644 --- a/vendor/rails/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb +++ b/vendor/rails/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb @@ -3,10 +3,18 @@ module ActiveSupport #: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 diff --git a/vendor/rails/activesupport/lib/active_support/core_ext/string/unicode.rb b/vendor/rails/activesupport/lib/active_support/core_ext/string/unicode.rb index 8532cc4..d4e5354 100644 --- a/vendor/rails/activesupport/lib/active_support/core_ext/string/unicode.rb +++ b/vendor/rails/activesupport/lib/active_support/core_ext/string/unicode.rb @@ -3,6 +3,8 @@ module ActiveSupport #:nodoc: module String #:nodoc: # Define methods for handling unicode data. module Unicode + + # removes incompatible String#chars from Ruby 1.8.7 def self.included(base) if RUBY_VERSION == '1.8.7' && '1.8.7'.respond_to?(:chars) base.class_eval { remove_method :chars } diff --git a/vendor/rails/activesupport/lib/active_support/core_ext/symbol.rb b/vendor/rails/activesupport/lib/active_support/core_ext/symbol.rb index 54f541a..d41d47e 100644 --- a/vendor/rails/activesupport/lib/active_support/core_ext/symbol.rb +++ b/vendor/rails/activesupport/lib/active_support/core_ext/symbol.rb @@ -1,4 +1,11 @@ -unless :test.respond_to?(:to_proc) +# Remove 1.8.7's incompatible method. +if :to_proc.respond_to?(:to_proc) && [1] != ([[1, 2]].map(&:first) rescue false) + class Symbol + remove_method :to_proc + end +end + +unless :to_proc.respond_to?(:to_proc) class Symbol # Turns the symbol into a simple proc, which is especially useful for enumerations. Examples: # diff --git a/vendor/rails/activesupport/lib/active_support/multibyte/chars.rb b/vendor/rails/activesupport/lib/active_support/multibyte/chars.rb index b30214d..79f92d0 100644 --- a/vendor/rails/activesupport/lib/active_support/multibyte/chars.rb +++ b/vendor/rails/activesupport/lib/active_support/multibyte/chars.rb @@ -40,13 +40,15 @@ module ActiveSupport::Multibyte #:nodoc: # core dumps. Don't go there. @string end - + # Make duck-typing with String possible - def respond_to?(method) - super || @string.respond_to?(method) || handler.respond_to?(method) || - (method.to_s =~ /(.*)!/ && handler.respond_to?($1)) || false + def respond_to?(method, include_priv = false) + super || @string.respond_to?(method, include_priv) || + handler.respond_to?(method, include_priv) || + (method.to_s =~ /(.*)!/ && handler.respond_to?($1, include_priv)) || + false end - + # Create a new Chars instance. def initialize(str) @string = str.respond_to?(:string) ? str.string : str -- libgit2 0.21.2