Commit f30ca75b3fb673968b6af23b3aadf807aec79ef4
1 parent
3f3fdf2f
Exists in
master
and in
8 other branches
ActionItem392: importing ruby1.8.7 compat changes
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1871 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
9 changed files
with
55 additions
and
23 deletions
Show diff stats
vendor/rails/actionpack/lib/action_controller/cgi_ext/cookie.rb
... | ... | @@ -79,7 +79,13 @@ class CGI #:nodoc: |
79 | 79 | buf |
80 | 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 | 89 | # pairs. |
84 | 90 | # |
85 | 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 | 8 | alias_method :to_datetime_default_s, :to_s |
9 | 9 | alias_method :to_s, :to_formatted_s |
10 | 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 | 13 | # Ruby 1.9 has DateTime#to_time which internally relies on Time. We define our own #to_time which allows |
14 | 14 | # DateTimes outside the range of what can be created with Time. |
15 | 15 | remove_method :to_time if base.instance_methods.include?(:to_time) |
16 | 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 | 24 | end |
18 | 25 | |
19 | 26 | # Convert to a formatted string - see DATE_FORMATS for predefined formats. | ... | ... |
vendor/rails/activesupport/lib/active_support/core_ext/enumerable.rb
1 | 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 | 5 | # Collect an enumerable into sets, grouped by the result of a block. Useful, |
3 | 6 | # for example, for grouping records by date. |
4 | 7 | # |
... | ... | @@ -19,7 +22,7 @@ module Enumerable |
19 | 22 | (groups[yield(element)] ||= []) << element |
20 | 23 | groups |
21 | 24 | end |
22 | - end if RUBY_VERSION < '1.9' | |
25 | + end unless [].respond_to?(:group_by) | |
23 | 26 | |
24 | 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 'active_support/core_ext/string/inflections' |
2 | 2 | require 'active_support/core_ext/string/conversions' |
3 | 3 | require 'active_support/core_ext/string/access' |
4 | 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 | 6 | require 'active_support/core_ext/string/unicode' |
7 | 7 | require 'active_support/core_ext/string/xchar' |
8 | 8 | |
... | ... | @@ -10,14 +10,7 @@ class String #:nodoc: |
10 | 10 | include ActiveSupport::CoreExtensions::String::Access |
11 | 11 | include ActiveSupport::CoreExtensions::String::Conversions |
12 | 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 | 15 | include ActiveSupport::CoreExtensions::String::Unicode |
23 | 16 | end | ... | ... |
vendor/rails/activesupport/lib/active_support/core_ext/string/iterators.rb
... | ... | @@ -5,6 +5,10 @@ module ActiveSupport #:nodoc: |
5 | 5 | module String #:nodoc: |
6 | 6 | # Custom string iterators |
7 | 7 | module Iterators |
8 | + def self.append_features(base) | |
9 | + super unless '1.9'.respond_to?(:each_char) | |
10 | + end | |
11 | + | |
8 | 12 | # Yields a single-character string for each character in the string. |
9 | 13 | # When $KCODE = 'UTF8', multi-byte characters are yielded appropriately. |
10 | 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 | 3 | module String #:nodoc: |
4 | 4 | # Additional string tests. |
5 | 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 | 18 | end |
11 | 19 | end |
12 | 20 | ... | ... |
vendor/rails/activesupport/lib/active_support/core_ext/string/unicode.rb
... | ... | @@ -3,6 +3,8 @@ module ActiveSupport #:nodoc: |
3 | 3 | module String #:nodoc: |
4 | 4 | # Define methods for handling unicode data. |
5 | 5 | module Unicode |
6 | + | |
7 | + # removes incompatible String#chars from Ruby 1.8.7 | |
6 | 8 | def self.included(base) |
7 | 9 | if RUBY_VERSION == '1.8.7' && '1.8.7'.respond_to?(:chars) |
8 | 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 | 9 | class Symbol |
3 | 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 | 40 | # core dumps. Don't go there. |
41 | 41 | @string |
42 | 42 | end |
43 | - | |
43 | + | |
44 | 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 | 50 | end |
49 | - | |
51 | + | |
50 | 52 | # Create a new Chars instance. |
51 | 53 | def initialize(str) |
52 | 54 | @string = str.respond_to?(:string) ? str.string : str | ... | ... |