diff options
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/cache/memory_store.rb | 8 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/benchmark.rb | 12 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/string/conversions.rb | 22 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/string/multibyte.rb | 7 | ||||
-rw-r--r-- | activesupport/lib/active_support/locale/en.yml | 5 | ||||
-rw-r--r-- | activesupport/lib/active_support/railtie.rb | 35 | ||||
-rw-r--r-- | activesupport/lib/active_support/rescuable.rb | 1 | ||||
-rw-r--r-- | activesupport/lib/active_support/values/time_zone.rb | 5 | ||||
-rw-r--r-- | activesupport/test/caching_test.rb | 7 | ||||
-rw-r--r-- | activesupport/test/core_ext/string_ext_test.rb | 12 | ||||
-rw-r--r-- | activesupport/test/time_zone_test.rb | 11 |
11 files changed, 89 insertions, 36 deletions
diff --git a/activesupport/lib/active_support/cache/memory_store.rb b/activesupport/lib/active_support/cache/memory_store.rb index e6085d97ec..379922f986 100644 --- a/activesupport/lib/active_support/cache/memory_store.rb +++ b/activesupport/lib/active_support/cache/memory_store.rb @@ -21,6 +21,12 @@ module ActiveSupport @data = {} end + def read_multi(*names) + results = {} + names.each { |n| results[n] = read(n) } + results + end + def read(name, options = nil) super do @data[name] @@ -45,7 +51,7 @@ module ActiveSupport end end - def exist?(name,options = nil) + def exist?(name, options = nil) super do @data.has_key?(name) end diff --git a/activesupport/lib/active_support/core_ext/benchmark.rb b/activesupport/lib/active_support/core_ext/benchmark.rb index ae57b152e8..2d110155a5 100644 --- a/activesupport/lib/active_support/core_ext/benchmark.rb +++ b/activesupport/lib/active_support/core_ext/benchmark.rb @@ -1,18 +1,6 @@ require 'benchmark' class << Benchmark - # Earlier Ruby had a slower implementation. - if RUBY_VERSION < '1.8.7' - remove_method :realtime - - def realtime - r0 = Time.now - yield - r1 = Time.now - r1.to_f - r0.to_f - end - end - def ms 1000 * realtime { yield } end diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb index 52946f9037..4cc36147f8 100644 --- a/activesupport/lib/active_support/core_ext/string/conversions.rb +++ b/activesupport/lib/active_support/core_ext/string/conversions.rb @@ -3,7 +3,27 @@ require 'active_support/core_ext/time/publicize_conversion_methods' require 'active_support/core_ext/time/calculations' class String - # 'a'.ord == 'a'[0] for Ruby 1.9 forward compatibility. + # Returns the codepoint of the first character of the string, assuming a + # single-byte character encoding: + # + # "a".ord # => 97 + # "à".ord # => 224, in ISO-8859-1 + # + # This method is defined in Ruby 1.8 for Ruby 1.9 forward compatibility on + # these character encodings. + # + # <tt>ActiveSupport::Multibyte::Chars#ord</tt> is forward compatible with + # Ruby 1.9 on UTF8 strings: + # + # "a".mb_chars.ord # => 97 + # "à".mb_chars.ord # => 224, in UTF8 + # + # Note that the 224 is different in both examples. In ISO-8859-1 "à" is + # represented as a single byte, 224. In UTF8 it is represented with two + # bytes, namely 195 and 160, but its Unicode codepoint is 224. If we + # call +ord+ on the UTF8 string "à" the return value will be 195. That is + # not an error, because UTF8 is unsupported, the call itself would be + # bogus. def ord self[0] end unless method_defined?(:ord) diff --git a/activesupport/lib/active_support/core_ext/string/multibyte.rb b/activesupport/lib/active_support/core_ext/string/multibyte.rb index 13208c6ee2..42e053d0f8 100644 --- a/activesupport/lib/active_support/core_ext/string/multibyte.rb +++ b/activesupport/lib/active_support/core_ext/string/multibyte.rb @@ -49,13 +49,6 @@ class String def is_utf8? ActiveSupport::Multibyte::Chars.consumes?(self) end - - unless '1.8.7 and later'.respond_to?(:chars) - def chars - ActiveSupport::Deprecation.warn('String#chars has been deprecated in favor of String#mb_chars.', caller) - mb_chars - end - end else def mb_chars #:nodoc self diff --git a/activesupport/lib/active_support/locale/en.yml b/activesupport/lib/active_support/locale/en.yml index e604c9ee8c..49ad192bf1 100644 --- a/activesupport/lib/active_support/locale/en.yml +++ b/activesupport/lib/active_support/locale/en.yml @@ -15,7 +15,10 @@ en: month_names: [~, January, February, March, April, May, June, July, August, September, October, November, December] abbr_month_names: [~, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec] # Used in date_select and datime_select. - order: [ :year, :month, :day ] + order: + - :year + - :month + - :day time: formats: diff --git a/activesupport/lib/active_support/railtie.rb b/activesupport/lib/active_support/railtie.rb index b8d54ff839..0243157e35 100644 --- a/activesupport/lib/active_support/railtie.rb +++ b/activesupport/lib/active_support/railtie.rb @@ -33,6 +33,7 @@ module I18n config.i18n = ActiveSupport::OrderedOptions.new config.i18n.railties_load_path = [] config.i18n.load_path = [] + config.i18n.fallbacks = ActiveSupport::OrderedOptions.new initializer "i18n.initialize" do ActiveSupport.on_load(:i18n) do @@ -53,6 +54,8 @@ module I18n app.config.i18n.load_path.unshift(*value) when :load_path I18n.load_path += value + when :fallbacks + init_fallbacks(value) if value && validate_fallbacks(value) else I18n.send("#{setting}=", value) end @@ -60,5 +63,37 @@ module I18n I18n.reload! end + + class << self + protected + + def init_fallbacks(fallbacks) + include_fallbacks_module + args = case fallbacks + when ActiveSupport::OrderedOptions + [*(fallbacks[:defaults] || []) << fallbacks[:map]].compact + when Hash, Array + Array.wrap(fallbacks) + else # TrueClass + [] + end + I18n.fallbacks = I18n::Locale::Fallbacks.new(*args) + end + + def include_fallbacks_module + I18n.backend.class.send(:include, I18n::Backend::Fallbacks) + end + + def validate_fallbacks(fallbacks) + case fallbacks + when ActiveSupport::OrderedOptions + !fallbacks.empty? + when TrueClass, Array, Hash + true + else + raise "Unexpected fallback type #{fallbacks.inspect}" + end + end + end end end
\ No newline at end of file diff --git a/activesupport/lib/active_support/rescuable.rb b/activesupport/lib/active_support/rescuable.rb index e4c1651acf..cd6f92cdfe 100644 --- a/activesupport/lib/active_support/rescuable.rb +++ b/activesupport/lib/active_support/rescuable.rb @@ -1,3 +1,4 @@ +require 'active_support/concern' require 'active_support/core_ext/class/attribute' require 'active_support/core_ext/proc' require 'active_support/core_ext/string/inflections' diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index 03b324764b..9db6bbafca 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -1,4 +1,5 @@ require 'active_support/core_ext/object/blank' +require 'active_support/core_ext/object/try' # The TimeZone class serves as a wrapper around TZInfo::Timezone instances. It allows us to do the following: # @@ -205,8 +206,8 @@ module ActiveSupport if @utc_offset @utc_offset else - @current_period ||= tzinfo.current_period - @current_period.utc_offset + @current_period ||= tzinfo.try(:current_period) + @current_period.try(:utc_offset) end end diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index d96f8e1de5..e62e7ef9aa 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -185,6 +185,13 @@ class MemoryStoreTest < ActiveSupport::TestCase @cache.write('foo', bar) assert_nothing_raised { bar.gsub!(/.*/, 'baz') } end + + def test_multi_get + @cache.write('foo', 1) + @cache.write('goo', 2) + result = @cache.read_multi('foo', 'goo') + assert_equal({'foo' => 1, 'goo' => 2}, result) + end end uses_memcached 'memcached backed store' do diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index 234e41c772..58ca215970 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -230,18 +230,6 @@ class CoreExtStringMultibyteTest < ActiveSupport::TestCase assert !BYTE_STRING.is_utf8? end - if RUBY_VERSION < '1.8.7' - def test_core_ext_adds_chars - assert UNICODE_STRING.respond_to?(:chars) - end - - def test_chars_warns_about_deprecation - assert_deprecated("String#chars") do - ''.chars - end - end - end - if RUBY_VERSION < '1.9' def test_mb_chars_returns_self_when_kcode_not_set with_kcode('none') do diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb index 68027f7c94..3b7fbb7808 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -274,6 +274,17 @@ class TimeZoneTest < Test::Unit::TestCase assert_raise(ArgumentError) { ActiveSupport::TimeZone[false] } end + def test_unknown_zone_shouldnt_have_tzinfo_nor_utc_offset + zone = ActiveSupport::TimeZone.create("bogus") + assert_nil zone.tzinfo + assert_nil zone.utc_offset + end + + def test_unknown_zone_with_utc_offset + zone = ActiveSupport::TimeZone.create("bogus", -21_600) + assert_equal(-21_600, zone.utc_offset) + end + def test_new assert_equal ActiveSupport::TimeZone["Central Time (US & Canada)"], ActiveSupport::TimeZone.new("Central Time (US & Canada)") end |