diff options
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG | 6 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/string/conversions.rb | 5 | ||||
-rw-r--r-- | activesupport/lib/active_support/deprecation/behaviors.rb | 21 | ||||
-rw-r--r-- | activesupport/lib/active_support/multibyte/chars.rb | 9 | ||||
-rw-r--r-- | activesupport/lib/active_support/multibyte/unicode.rb | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/railtie.rb | 32 | ||||
-rw-r--r-- | activesupport/lib/active_support/testing/performance.rb | 54 | ||||
-rw-r--r-- | activesupport/lib/active_support/values/time_zone.rb | 6 | ||||
-rw-r--r-- | activesupport/lib/active_support/values/unicode_tables.dat | bin | 710743 -> 813343 bytes | |||
-rw-r--r-- | activesupport/test/core_ext/time_with_zone_test.rb | 4 | ||||
-rw-r--r-- | activesupport/test/multibyte_chars_test.rb | 15 | ||||
-rw-r--r-- | activesupport/test/time_zone_test.rb | 7 |
12 files changed, 96 insertions, 65 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 59ad57ede8..60586cf99a 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,11 @@ *Rails 3.0.0 [Release Candidate] (unreleased)* +* Deprecation behavior is no longer hardcoded to the name of the environment. + Instead, it is set via config.active_support.deprecation and can be one + of :log, :stderr or :notify. :notify is a new style that sends the warning + via ActiveSupport::Notifications, and is the new default for production + [Yehuda Katz] + * Renamed ActiveSupport::Dependecies.load_(once_)paths to autoload_(once_)paths. [fxn] * Added ActiveSupport::FileUpdateChecker to execute a block only if a set of files changed, used by Router and I18n locale files. [José Valim] diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb index af277f9995..5b2cb6e331 100644 --- a/activesupport/lib/active_support/core_ext/string/conversions.rb +++ b/activesupport/lib/active_support/core_ext/string/conversions.rb @@ -28,9 +28,8 @@ class String self[0] end unless method_defined?(:ord) - def getbyte(index) - self[index] - end if RUBY_VERSION < '1.9' + # +getbyte+ backport from Ruby 1.9 + alias_method :getbyte, :[] unless method_defined?(:getbyte) # Form can be either :utc (default) or :local. def to_time(form = :utc) diff --git a/activesupport/lib/active_support/deprecation/behaviors.rb b/activesupport/lib/active_support/deprecation/behaviors.rb index 578c025fcf..feb1508586 100644 --- a/activesupport/lib/active_support/deprecation/behaviors.rb +++ b/activesupport/lib/active_support/deprecation/behaviors.rb @@ -1,28 +1,27 @@ +require "active_support/notifications" + module ActiveSupport module Deprecation class << self - # Behavior is a block that takes a message argument. - attr_writer :behavior - # Whether to print a backtrace along with the warning. attr_accessor :debug def behavior - @behavior ||= default_behavior + @behavior ||= DEFAULT_BEHAVIORS[:stderr] end - def default_behavior - Deprecation::DEFAULT_BEHAVIORS[defined?(Rails.env) ? Rails.env.to_s : 'test'] + def behavior=(behavior) + @behavior = DEFAULT_BEHAVIORS[behavior] || behavior end end - # Default warning behaviors per Rails.env. Ignored in production. + # Default warning behaviors per Rails.env. DEFAULT_BEHAVIORS = { - 'test' => Proc.new { |message, callstack| + :stderr => Proc.new { |message, callstack| $stderr.puts(message) $stderr.puts callstack.join("\n ") if debug }, - 'development' => Proc.new { |message, callstack| + :log => Proc.new { |message, callstack| logger = if defined?(Rails) && Rails.logger Rails.logger @@ -32,6 +31,10 @@ module ActiveSupport end logger.warn message logger.debug callstack.join("\n ") if debug + }, + :notify => Proc.new { |message, callstack| + ActiveSupport::Notifications.instrument("deprecation.rails", + :message => message, :callstack => callstack) } } end diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb index c107aad6bb..8823e4a5ed 100644 --- a/activesupport/lib/active_support/multibyte/chars.rb +++ b/activesupport/lib/active_support/multibyte/chars.rb @@ -105,7 +105,7 @@ module ActiveSupport #:nodoc: # Example: # ('Café'.mb_chars + ' périferôl').to_s #=> "Café périferôl" def +(other) - self << other + chars(@wrapped_string + other) end # Like <tt>String#=~</tt> only it returns the character offset (in codepoints) instead of the byte offset. @@ -316,11 +316,12 @@ module ActiveSupport #:nodoc: result = @wrapped_string.slice(*args) elsif args.size == 1 && args[0].kind_of?(Numeric) character = Unicode.u_unpack(@wrapped_string)[args[0]] - result = character.nil? ? nil : [character].pack('U') + result = character && [character].pack('U') else - result = Unicode.u_unpack(@wrapped_string).slice(*args).pack('U*') + cps = Unicode.u_unpack(@wrapped_string).slice(*args) + result = cps && cps.pack('U*') end - result.nil? ? nil : chars(result) + result && chars(result) end alias_method :[], :slice diff --git a/activesupport/lib/active_support/multibyte/unicode.rb b/activesupport/lib/active_support/multibyte/unicode.rb index f91e50c755..11c72d873b 100644 --- a/activesupport/lib/active_support/multibyte/unicode.rb +++ b/activesupport/lib/active_support/multibyte/unicode.rb @@ -9,7 +9,7 @@ module ActiveSupport NORMALIZATION_FORMS = [:c, :kc, :d, :kd] # The Unicode version that is supported by the implementation - UNICODE_VERSION = '5.1.0' + UNICODE_VERSION = '5.2.0' # The default normalization used for operations that require normalization. It can be set to any of the # normalizations in NORMALIZATION_FORMS. diff --git a/activesupport/lib/active_support/railtie.rb b/activesupport/lib/active_support/railtie.rb index 1f32f8718f..c2deba3b1b 100644 --- a/activesupport/lib/active_support/railtie.rb +++ b/activesupport/lib/active_support/railtie.rb @@ -12,6 +12,36 @@ module ActiveSupport require 'active_support/whiny_nil' if app.config.whiny_nils end + initializer "active_support.deprecation_behavior" do |app| + if deprecation = app.config.active_support.deprecation + ActiveSupport::Deprecation.behavior = deprecation + else + defaults = {"development" => :log, + "production" => :notify, + "test" => :stderr} + + env = Rails.env + + if defaults.key?(env) + msg = "You did not specify how you would like Rails to report " \ + "deprecation notices for your #{env} environment, please " \ + "set config.active_support.deprecation to :#{defaults[env]} " \ + "at config/environments/#{env}.rb" + + warn msg + ActiveSupport::Deprecation.behavior = defaults[env] + else + msg = "You did not specify how you would like Rails to report " \ + "deprecation notices for your #{env} environment, please " \ + "set config.active_support.deprecation to :log, :notify or " \ + ":stderr at config/environments/#{env}.rb" + + warn msg + ActiveSupport::Deprecation.behavior = :stderr + end + end + end + # Sets the default value for Time.zone # If assigned value cannot be matched to a TimeZone, an exception will be raised. initializer "active_support.initialize_time_zone" do |app| @@ -27,4 +57,4 @@ module ActiveSupport Time.zone_default = zone_default end end -end
\ No newline at end of file +end diff --git a/activesupport/lib/active_support/testing/performance.rb b/activesupport/lib/active_support/testing/performance.rb index cd628a956d..a124c6e0ca 100644 --- a/activesupport/lib/active_support/testing/performance.rb +++ b/activesupport/lib/active_support/testing/performance.rb @@ -260,16 +260,14 @@ begin end protected - # Ruby 1.9 + extented GC profiler patch - if defined?(GC::Profiler) and GC::Profiler.respond_to?(:data) + # Ruby 1.9 with GC::Profiler + if defined?(GC::Profiler) def with_gc_stats - GC.start - GC.disable GC::Profiler.enable + GC.start yield ensure GC::Profiler.disable - GC.enable end # Ruby 1.8 + ruby-prof wrapper (enable/disable stats for Benchmarker) @@ -294,7 +292,7 @@ begin end def format(measurement) - if measurement < 2 + if measurement < 1 '%d ms' % (measurement * 1000) else '%.2f sec' % measurement @@ -335,14 +333,10 @@ begin class Memory < Base Mode = RubyProf::MEMORY if RubyProf.const_defined?(:MEMORY) - # Ruby 1.9 + extended GC profiler patch - if defined?(GC::Profiler) and GC::Profiler.respond_to?(:data) + # Ruby 1.9 + GCdata patch + if GC.respond_to?(:malloc_allocated_size) def measure - GC.enable - GC.start - kb = GC::Profiler.data.last[:HEAP_USE_SIZE] / 1024.0 - GC.disable - kb + GC.malloc_allocated_size / 1024.0 end # Ruby 1.8 + ruby-prof wrapper @@ -360,14 +354,10 @@ begin class Objects < Base Mode = RubyProf::ALLOCATIONS if RubyProf.const_defined?(:ALLOCATIONS) - # Ruby 1.9 + extented GC profiler patch - if defined?(GC::Profiler) and GC::Profiler.respond_to?(:data) + # Ruby 1.9 + GCdata patch + if GC.respond_to?(:malloc_allocations) def measure - GC.enable - GC.start - count = GC::Profiler.data.last[:HEAP_TOTAL_OBJECTS] - GC.disable - count + GC.malloc_allocations end # Ruby 1.8 + ruby-prof wrapper @@ -385,14 +375,10 @@ begin class GcRuns < Base Mode = RubyProf::GC_RUNS if RubyProf.const_defined?(:GC_RUNS) - # Ruby 1.9 + extented GC profiler patch - if defined?(GC::Profiler) and GC::Profiler.respond_to?(:data) + # Ruby 1.9 + if GC.respond_to?(:count) def measure - GC.enable - GC.start - count = GC::Profiler.data.last[:GC_RUNS] - GC.disable - count + GC.count end # Ruby 1.8 + ruby-prof wrapper @@ -410,25 +396,21 @@ begin class GcTime < Base Mode = RubyProf::GC_TIME if RubyProf.const_defined?(:GC_TIME) - # Ruby 1.9 + extented GC profiler patch - if defined?(GC::Profiler) and GC::Profiler.respond_to?(:data) + # Ruby 1.9 with GC::Profiler + if GC.respond_to?(:total_time) def measure - GC.enable - GC.start - sec = GC::Profiler.data.inject(0) { |total, run| total += run[:GC_TIME] } - GC.disable - sec + GC::Profiler.total_time end # Ruby 1.8 + ruby-prof wrapper elsif RubyProf.respond_to?(:measure_gc_time) def measure - RubyProf.measure_gc_time + RubyProf.measure_gc_time / 1000 end end def format(measurement) - '%d ms' % (measurement / 1000) + '%.2f ms' % measurement end end end diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index 0a08016522..05b40298d3 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -350,7 +350,11 @@ module ActiveSupport def [](arg) case arg when String - zones_map[arg] ||= lookup(arg) + begin + zones_map[arg] ||= lookup(arg).tap { |tz| tz.utc_offset } + rescue TZInfo::InvalidTimezoneIdentifier + nil + end when Numeric, ActiveSupport::Duration arg *= 3600 if arg.abs <= 13 all.find { |z| z.utc_offset == arg.to_i } diff --git a/activesupport/lib/active_support/values/unicode_tables.dat b/activesupport/lib/active_support/values/unicode_tables.dat Binary files differindex 10f2cae465..4fe0268cca 100644 --- a/activesupport/lib/active_support/values/unicode_tables.dat +++ b/activesupport/lib/active_support/values/unicode_tables.dat diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index cf11f4d28f..5ce4277672 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -832,9 +832,7 @@ class TimeWithZoneMethodsForTimeAndDateTimeTest < Test::Unit::TestCase def test_time_zone_setter_with_invalid_zone Time.zone = 'foo' - assert_not_nil Time.zone - assert_equal 'foo', Time.zone.name - assert_raise(TZInfo::InvalidTimezoneIdentifier) { Time.zone.utc_offset } + assert_nil Time.zone Time.zone = -15.hours assert_nil Time.zone diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb index 602828ef5f..610295fa89 100644 --- a/activesupport/test/multibyte_chars_test.rb +++ b/activesupport/test/multibyte_chars_test.rb @@ -49,13 +49,15 @@ class MultibyteCharsTest < Test::Unit::TestCase end def test_should_concatenate - assert_equal 'ab', 'a'.mb_chars + 'b' - assert_equal 'ab', 'a' + 'b'.mb_chars - assert_equal 'ab', 'a'.mb_chars + 'b'.mb_chars + mb_a = 'a'.mb_chars + mb_b = 'b'.mb_chars + assert_equal 'ab', mb_a + 'b' + assert_equal 'ab', 'a' + mb_b + assert_equal 'ab', mb_a + mb_b - assert_equal 'ab', 'a'.mb_chars << 'b' - assert_equal 'ab', 'a' << 'b'.mb_chars - assert_equal 'ab', 'a'.mb_chars << 'b'.mb_chars + assert_equal 'ab', mb_a << 'b' + assert_equal 'ab', 'a' << mb_b + assert_equal 'abb', mb_a << mb_b end def test_consumes_utf8_strings @@ -395,6 +397,7 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase assert_equal 'こ', @chars.slice(0) assert_equal 'わ', @chars.slice(3) assert_equal nil, ''.mb_chars.slice(-1..1) + assert_equal nil, ''.mb_chars.slice(-1, 1) assert_equal '', ''.mb_chars.slice(0..10) assert_equal 'にちわ', @chars.slice(1..3) assert_equal 'にちわ', @chars.slice(1, 3) diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb index 620623b389..af6eee69e5 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -268,7 +268,7 @@ class TimeZoneTest < Test::Unit::TestCase end def test_index - assert_not_nil ActiveSupport::TimeZone["bogus"] + assert_nil ActiveSupport::TimeZone["bogus"] assert_instance_of ActiveSupport::TimeZone, ActiveSupport::TimeZone["Central Time (US & Canada)"] assert_instance_of ActiveSupport::TimeZone, ActiveSupport::TimeZone[8] assert_raise(ArgumentError) { ActiveSupport::TimeZone[false] } @@ -285,6 +285,11 @@ class TimeZoneTest < Test::Unit::TestCase assert_equal(-21_600, zone.utc_offset) end + def test_unknown_zones_dont_store_mapping_keys + ActiveSupport::TimeZone["bogus"] + assert !ActiveSupport::TimeZone.zones_map.key?("bogus") + end + def test_new assert_equal ActiveSupport::TimeZone["Central Time (US & Canada)"], ActiveSupport::TimeZone.new("Central Time (US & Canada)") end |