提交 20cdaddf 编写于 作者: J Jeremy Kemper

Ruby 1.9.2: work around changes to flatten and nil.to_str

上级 7ad461b4
...@@ -43,7 +43,8 @@ module Strategy ...@@ -43,7 +43,8 @@ module Strategy
# ActiveSupport::Cache.lookup_store(MyOwnCacheStore.new) # ActiveSupport::Cache.lookup_store(MyOwnCacheStore.new)
# # => returns MyOwnCacheStore.new # # => returns MyOwnCacheStore.new
def self.lookup_store(*store_option) def self.lookup_store(*store_option)
store, *parameters = *([ store_option ].flatten) store = store_option.shift
parameters = store_option
case store case store
when Symbol when Symbol
......
require 'active_support/time' require 'active_support/time'
require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/hash/reverse_merge' require 'active_support/core_ext/hash/reverse_merge'
class Hash class Hash
...@@ -138,7 +139,7 @@ def typecast_xml_value(value) ...@@ -138,7 +139,7 @@ def typecast_xml_value(value)
case value.class.to_s case value.class.to_s
when 'Hash' when 'Hash'
if value['type'] == 'array' if value['type'] == 'array'
child_key, entries = value.detect { |k,v| k != 'type' } # child_key is throwaway child_key, entries = Array.wrap(value.detect { |k,v| k != 'type' }) # child_key is throwaway
if entries.nil? || (c = value['__content__'] && c.blank?) if entries.nil? || (c = value['__content__'] && c.blank?)
[] []
else else
......
...@@ -339,7 +339,7 @@ def loadable_constants_for_path(path, bases = load_paths) ...@@ -339,7 +339,7 @@ def loadable_constants_for_path(path, bases = load_paths)
next next
end end
[ nesting_camel ] [ nesting_camel ]
end.flatten.compact.uniq end.compact.flatten.compact.uniq
end end
# Search for a file in load_paths matching the provided suffix. # Search for a file in load_paths matching the provided suffix.
......
require 'active_support/core_ext/array/extract_options' require 'active_support/core_ext/array/extract_options'
require 'active_support/core_ext/array/wrap'
module ActiveSupport module ActiveSupport
# Callbacks are hooks into the lifecycle of an object that allow you to trigger logic # Callbacks are hooks into the lifecycle of an object that allow you to trigger logic
...@@ -194,8 +195,8 @@ def evaluate_method(method, *args, &block) ...@@ -194,8 +195,8 @@ def evaluate_method(method, *args, &block)
end end
def should_run_callback?(*args) def should_run_callback?(*args)
[options[:if]].flatten.compact.all? { |a| evaluate_method(a, *args) } && Array.wrap(options[:if]).flatten.compact.all? { |a| evaluate_method(a, *args) } &&
![options[:unless]].flatten.compact.any? { |a| evaluate_method(a, *args) } !Array.wrap(options[:unless]).flatten.compact.any? { |a| evaluate_method(a, *args) }
end end
end end
......
...@@ -23,15 +23,18 @@ def decode(json) ...@@ -23,15 +23,18 @@ def decode(json)
private private
def convert_dates_from(data) def convert_dates_from(data)
case data case data
when DATE_REGEX when nil
DateTime.parse(data) nil
when Array when DATE_REGEX
data.map! { |d| convert_dates_from(d) } DateTime.parse(data)
when Hash when Array
data.each do |key, value| data.map! { |d| convert_dates_from(d) }
data[key] = convert_dates_from(value) when Hash
end data.each do |key, value|
else data data[key] = convert_dates_from(value)
end
else
data
end end
end end
end end
......
...@@ -228,8 +228,8 @@ def test_should_know_if_one_includes_the_other ...@@ -228,8 +228,8 @@ def test_should_know_if_one_includes_the_other
assert !@chars.include?('a') assert !@chars.include?('a')
end end
def test_include_raises_type_error_when_nil_is_passed def test_include_raises_when_nil_is_passed
assert_raise(TypeError) do assert_raise(RUBY_VERSION >= '1.9.2' ? NoMethodError : TypeError) do
@chars.include?(nil) @chars.include?(nil)
end end
end end
...@@ -659,4 +659,4 @@ class MultibyteInternalsTest < ActiveSupport::TestCase ...@@ -659,4 +659,4 @@ class MultibyteInternalsTest < ActiveSupport::TestCase
"Expected byte offset #{byte_offset} to translate to #{character_offset}" "Expected byte offset #{byte_offset} to translate to #{character_offset}"
end end
end end
end end
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册