Commit f30ca75b3fb673968b6af23b3aadf807aec79ef4

Authored by AntonioTerceiro
1 parent 3f3fdf2f

ActionItem392: importing ruby1.8.7 compat changes


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1871 3f533792-8f58-4932-b0fe-aaf55b0a4547
vendor/rails/actionpack/lib/action_controller/cgi_ext/cookie.rb
@@ -79,7 +79,13 @@ class CGI #:nodoc: @@ -79,7 +79,13 @@ class CGI #:nodoc:
79 buf 79 buf
80 end 80 end
81 81
82 - # Parse a raw cookie string into a hash of cookie-name=>Cookie 82 + # FIXME: work around broken 1.8.7 DelegateClass#respond_to?
  83 + def respond_to?(method, include_private = false)
  84 + return true if super(method)
  85 + return __getobj__.respond_to?(method, include_private)
  86 + end
  87 +
  88 + # Parses a raw cookie string into a hash of <tt>cookie-name => cookie-object</tt>
83 # pairs. 89 # pairs.
84 # 90 #
85 # cookies = CGI::Cookie::parse("raw_cookie_string") 91 # cookies = CGI::Cookie::parse("raw_cookie_string")
vendor/rails/activesupport/lib/active_support/core_ext/date_time/conversions.rb
@@ -8,12 +8,19 @@ module ActiveSupport #:nodoc: @@ -8,12 +8,19 @@ module ActiveSupport #:nodoc:
8 alias_method :to_datetime_default_s, :to_s 8 alias_method :to_datetime_default_s, :to_s
9 alias_method :to_s, :to_formatted_s 9 alias_method :to_s, :to_formatted_s
10 alias_method :default_inspect, :inspect 10 alias_method :default_inspect, :inspect
11 - alias_method :inspect, :readable_inspect 11 + alias_method :to_default_s, :to_s unless (instance_methods(false) & [:to_s, 'to_s']).empty?
12 12
13 # Ruby 1.9 has DateTime#to_time which internally relies on Time. We define our own #to_time which allows 13 # Ruby 1.9 has DateTime#to_time which internally relies on Time. We define our own #to_time which allows
14 # DateTimes outside the range of what can be created with Time. 14 # DateTimes outside the range of what can be created with Time.
15 remove_method :to_time if base.instance_methods.include?(:to_time) 15 remove_method :to_time if base.instance_methods.include?(:to_time)
16 end 16 end
  17 +
  18 + super
  19 +
  20 + base.class_eval do
  21 + alias_method :to_s, :to_formatted_s
  22 + alias_method :inspect, :readable_inspect
  23 + end
17 end 24 end
18 25
19 # Convert to a formatted string - see DATE_FORMATS for predefined formats. 26 # Convert to a formatted string - see DATE_FORMATS for predefined formats.
vendor/rails/activesupport/lib/active_support/core_ext/enumerable.rb
1 module Enumerable 1 module Enumerable
  2 + # Ruby 1.8.7 introduces group_by, but the result isn't ordered. Override it.
  3 + remove_method(:group_by) if [].respond_to?(:group_by) && RUBY_VERSION < '1.9'
  4 +
2 # Collect an enumerable into sets, grouped by the result of a block. Useful, 5 # Collect an enumerable into sets, grouped by the result of a block. Useful,
3 # for example, for grouping records by date. 6 # for example, for grouping records by date.
4 # 7 #
@@ -19,7 +22,7 @@ module Enumerable @@ -19,7 +22,7 @@ module Enumerable
19 (groups[yield(element)] ||= []) << element 22 (groups[yield(element)] ||= []) << element
20 groups 23 groups
21 end 24 end
22 - end if RUBY_VERSION < '1.9' 25 + end unless [].respond_to?(:group_by)
23 26
24 # Calculates a sum from the elements. Examples: 27 # Calculates a sum from the elements. Examples:
25 # 28 #
vendor/rails/activesupport/lib/active_support/core_ext/string.rb
@@ -2,7 +2,7 @@ require &#39;active_support/core_ext/string/inflections&#39; @@ -2,7 +2,7 @@ require &#39;active_support/core_ext/string/inflections&#39;
2 require 'active_support/core_ext/string/conversions' 2 require 'active_support/core_ext/string/conversions'
3 require 'active_support/core_ext/string/access' 3 require 'active_support/core_ext/string/access'
4 require 'active_support/core_ext/string/starts_ends_with' 4 require 'active_support/core_ext/string/starts_ends_with'
5 -require 'active_support/core_ext/string/iterators' unless 'test'.respond_to?(:each_char) 5 +require 'active_support/core_ext/string/iterators'
6 require 'active_support/core_ext/string/unicode' 6 require 'active_support/core_ext/string/unicode'
7 require 'active_support/core_ext/string/xchar' 7 require 'active_support/core_ext/string/xchar'
8 8
@@ -10,14 +10,7 @@ class String #:nodoc: @@ -10,14 +10,7 @@ class String #:nodoc:
10 include ActiveSupport::CoreExtensions::String::Access 10 include ActiveSupport::CoreExtensions::String::Access
11 include ActiveSupport::CoreExtensions::String::Conversions 11 include ActiveSupport::CoreExtensions::String::Conversions
12 include ActiveSupport::CoreExtensions::String::Inflections 12 include ActiveSupport::CoreExtensions::String::Inflections
13 - if RUBY_VERSION < '1.9'  
14 - include ActiveSupport::CoreExtensions::String::StartsEndsWith  
15 - else  
16 - alias starts_with? start_with?  
17 - alias ends_with? end_with?  
18 - end  
19 - if defined? ActiveSupport::CoreExtensions::String::Iterators  
20 - include ActiveSupport::CoreExtensions::String::Iterators  
21 - end 13 + include ActiveSupport::CoreExtensions::String::StartsEndsWith
  14 + include ActiveSupport::CoreExtensions::String::Iterators
22 include ActiveSupport::CoreExtensions::String::Unicode 15 include ActiveSupport::CoreExtensions::String::Unicode
23 end 16 end
vendor/rails/activesupport/lib/active_support/core_ext/string/iterators.rb
@@ -5,6 +5,10 @@ module ActiveSupport #:nodoc: @@ -5,6 +5,10 @@ module ActiveSupport #:nodoc:
5 module String #:nodoc: 5 module String #:nodoc:
6 # Custom string iterators 6 # Custom string iterators
7 module Iterators 7 module Iterators
  8 + def self.append_features(base)
  9 + super unless '1.9'.respond_to?(:each_char)
  10 + end
  11 +
8 # Yields a single-character string for each character in the string. 12 # Yields a single-character string for each character in the string.
9 # When $KCODE = 'UTF8', multi-byte characters are yielded appropriately. 13 # When $KCODE = 'UTF8', multi-byte characters are yielded appropriately.
10 def each_char 14 def each_char
vendor/rails/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb
@@ -3,10 +3,18 @@ module ActiveSupport #:nodoc: @@ -3,10 +3,18 @@ module ActiveSupport #:nodoc:
3 module String #:nodoc: 3 module String #:nodoc:
4 # Additional string tests. 4 # Additional string tests.
5 module StartsEndsWith 5 module StartsEndsWith
6 - def self.included(base)  
7 - base.class_eval do  
8 - alias_method :start_with?, :starts_with?  
9 - alias_method :end_with?, :ends_with? 6 + def self.append_features(base)
  7 + if '1.8.7 and up'.respond_to?(:start_with?)
  8 + base.class_eval do
  9 + alias_method :starts_with?, :start_with?
  10 + alias_method :ends_with?, :end_with?
  11 + end
  12 + else
  13 + super
  14 + base.class_eval do
  15 + alias_method :start_with?, :starts_with?
  16 + alias_method :end_with?, :ends_with?
  17 + end
10 end 18 end
11 end 19 end
12 20
vendor/rails/activesupport/lib/active_support/core_ext/string/unicode.rb
@@ -3,6 +3,8 @@ module ActiveSupport #:nodoc: @@ -3,6 +3,8 @@ module ActiveSupport #:nodoc:
3 module String #:nodoc: 3 module String #:nodoc:
4 # Define methods for handling unicode data. 4 # Define methods for handling unicode data.
5 module Unicode 5 module Unicode
  6 +
  7 + # removes incompatible String#chars from Ruby 1.8.7
6 def self.included(base) 8 def self.included(base)
7 if RUBY_VERSION == '1.8.7' && '1.8.7'.respond_to?(:chars) 9 if RUBY_VERSION == '1.8.7' && '1.8.7'.respond_to?(:chars)
8 base.class_eval { remove_method :chars } 10 base.class_eval { remove_method :chars }
vendor/rails/activesupport/lib/active_support/core_ext/symbol.rb
1 -unless :test.respond_to?(:to_proc) 1 +# Remove 1.8.7's incompatible method.
  2 +if :to_proc.respond_to?(:to_proc) && [1] != ([[1, 2]].map(&:first) rescue false)
  3 + class Symbol
  4 + remove_method :to_proc
  5 + end
  6 +end
  7 +
  8 +unless :to_proc.respond_to?(:to_proc)
2 class Symbol 9 class Symbol
3 # Turns the symbol into a simple proc, which is especially useful for enumerations. Examples: 10 # Turns the symbol into a simple proc, which is especially useful for enumerations. Examples:
4 # 11 #
vendor/rails/activesupport/lib/active_support/multibyte/chars.rb
@@ -40,13 +40,15 @@ module ActiveSupport::Multibyte #:nodoc: @@ -40,13 +40,15 @@ module ActiveSupport::Multibyte #:nodoc:
40 # core dumps. Don't go there. 40 # core dumps. Don't go there.
41 @string 41 @string
42 end 42 end
43 - 43 +
44 # Make duck-typing with String possible 44 # Make duck-typing with String possible
45 - def respond_to?(method)  
46 - super || @string.respond_to?(method) || handler.respond_to?(method) ||  
47 - (method.to_s =~ /(.*)!/ && handler.respond_to?($1)) || false 45 + def respond_to?(method, include_priv = false)
  46 + super || @string.respond_to?(method, include_priv) ||
  47 + handler.respond_to?(method, include_priv) ||
  48 + (method.to_s =~ /(.*)!/ && handler.respond_to?($1, include_priv)) ||
  49 + false
48 end 50 end
49 - 51 +
50 # Create a new Chars instance. 52 # Create a new Chars instance.
51 def initialize(str) 53 def initialize(str)
52 @string = str.respond_to?(:string) ? str.string : str 54 @string = str.respond_to?(:string) ? str.string : str