From d868cb4f8a84b6275b6407b20bb3ba939a53681a Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 1 Apr 2010 13:36:45 -0700 Subject: Prep for beta2, depend on latest Bundler --- activesupport/lib/active_support/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/version.rb b/activesupport/lib/active_support/version.rb index 831204693f..3ce11e59d2 100644 --- a/activesupport/lib/active_support/version.rb +++ b/activesupport/lib/active_support/version.rb @@ -3,7 +3,7 @@ module ActiveSupport MAJOR = 3 MINOR = 0 TINY = 0 - BUILD = "beta1" + BUILD = "beta2" STRING = [MAJOR, MINOR, TINY, BUILD].join('.') end -- cgit v1.2.3 From d956003fa499d22689db8a10712fc7bcb9dbc5c8 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 1 Apr 2010 13:46:04 -0700 Subject: Neat and tidy, I say --- activesupport/activesupport.gemspec | 1 + 1 file changed, 1 insertion(+) (limited to 'activesupport') diff --git a/activesupport/activesupport.gemspec b/activesupport/activesupport.gemspec index bfb1e83002..ad1401bfa9 100644 --- a/activesupport/activesupport.gemspec +++ b/activesupport/activesupport.gemspec @@ -6,6 +6,7 @@ Gem::Specification.new do |s| s.version = version s.summary = 'A toolkit of support libraries and Ruby core extensions extracted from the Rails framework.' s.description = 'A toolkit of support libraries and Ruby core extensions extracted from the Rails framework. Rich support for multibyte strings, internationalization, time zones, and testing.' + s.required_ruby_version = '>= 1.8.7' s.author = 'David Heinemeier Hansson' -- cgit v1.2.3 From d2a48852a197190ecead6650aa62c7df4c3136ee Mon Sep 17 00:00:00 2001 From: wycats Date: Thu, 1 Apr 2010 13:54:53 -0700 Subject: Updated changelogs --- activesupport/CHANGELOG | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activesupport') diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 3822abcab6..60f7c0e638 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,10 @@ *Rails 3.0 (pending)* +* Reduced load time by deferring configuration of classes using + ActiveSupport::on_load(:component_name) [YK] + +* Rename #metaclass to #singleton_class now that ruby-core has decided [JK] + * New assertions assert_blank and assert_present. #4299 [Juanjo Bazan] * Use Object#singleton_class instead of #metaclass. Prefer Ruby's choice. [Jeremy Kemper] -- cgit v1.2.3 From c1883e75b38be79cc547890b2c83619351da1c95 Mon Sep 17 00:00:00 2001 From: wycats Date: Thu, 1 Apr 2010 14:04:55 -0700 Subject: Updated changelogs to differentiate beta1 and beta2 --- activesupport/CHANGELOG | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'activesupport') diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 60f7c0e638..48c4af7f74 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,4 +1,4 @@ -*Rails 3.0 (pending)* +*Rails 3.0.0 [beta 2] (pending)* * Reduced load time by deferring configuration of classes using ActiveSupport::on_load(:component_name) [YK] @@ -11,8 +11,7 @@ * JSON backend for YAJL. Preferred if available. #2666 [Brian Lopez] - -*Rails 3.0.0 [beta] (February 4, 2010)* +*Rails 3.0.0 [beta 1] (February 4, 2010)* * Introduce class_attribute to declare inheritable class attributes. Writing an attribute on a subclass behaves just like overriding the superclass reader method. Unifies and replaces most usage of cattr_accessor, class_inheritable_attribute, superclass_delegating_attribute, and extlib_inheritable_attribute. [Jeremy Kemper, Yehuda Katz] -- cgit v1.2.3 From f0364d87f03d58312bcab1b2f17b5b56b6c72653 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 1 Apr 2010 14:20:03 -0700 Subject: Release is today, yo --- activesupport/CHANGELOG | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 48c4af7f74..b9f565c71d 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,4 +1,4 @@ -*Rails 3.0.0 [beta 2] (pending)* +*Rails 3.0.0 [beta 2] (April 1st, 2010)* * Reduced load time by deferring configuration of classes using ActiveSupport::on_load(:component_name) [YK] @@ -11,6 +11,7 @@ * JSON backend for YAJL. Preferred if available. #2666 [Brian Lopez] + *Rails 3.0.0 [beta 1] (February 4, 2010)* * Introduce class_attribute to declare inheritable class attributes. Writing an attribute on a subclass behaves just like overriding the superclass reader method. Unifies and replaces most usage of cattr_accessor, class_inheritable_attribute, superclass_delegating_attribute, and extlib_inheritable_attribute. [Jeremy Kemper, Yehuda Katz] -- cgit v1.2.3 From ab281f511ccb3893ea077fe8a7bb78cdd2db0885 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 1 Apr 2010 17:18:24 -0700 Subject: Fix class_attribute so that it works with singleton classes. --- activesupport/lib/active_support/core_ext/class/attribute.rb | 2 +- activesupport/test/core_ext/class/attribute_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/class/attribute.rb b/activesupport/lib/active_support/core_ext/class/attribute.rb index 9631a7d242..577d5cbf45 100644 --- a/activesupport/lib/active_support/core_ext/class/attribute.rb +++ b/activesupport/lib/active_support/core_ext/class/attribute.rb @@ -50,7 +50,7 @@ class Class singleton_class.send(:define_method, attr) { value } end - define_method(attr) { self.class.send(attr) } + define_method(attr) { self.singleton_class.send(attr) } define_method(:"#{attr}?") { !!send(attr) } define_method(:"#{attr}=") do |value| singleton_class.remove_possible_method(attr) diff --git a/activesupport/test/core_ext/class/attribute_test.rb b/activesupport/test/core_ext/class/attribute_test.rb index 06b4cf075f..24aa5c0eba 100644 --- a/activesupport/test/core_ext/class/attribute_test.rb +++ b/activesupport/test/core_ext/class/attribute_test.rb @@ -59,4 +59,10 @@ class ClassAttributeTest < ActiveSupport::TestCase object = Class.new { class_attribute :setting, :instance_writer => false }.new assert_raise(NoMethodError) { object.setting = 'boom' } end + + test 'works well with singleton classes' do + object = @klass.new + object.singleton_class.setting = 'foo' + assert_equal 'foo', object.setting + end end -- cgit v1.2.3 From 90e3343ae5f9daa1458fc37e220d89cdb41b3185 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 2 Apr 2010 16:43:15 -0300 Subject: utc_offset is no longer required on TimeZone and if it's not supplied we delegate to TZInfo --- .../lib/active_support/values/time_zone.rb | 79 +++++----------------- 1 file changed, 18 insertions(+), 61 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index 945cdd5278..b9766a236a 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -194,7 +194,7 @@ module ActiveSupport # offset is the number of seconds that this time zone is offset from UTC # (GMT). Seconds were chosen as the offset unit because that is the unit that # Ruby uses to represent time zone offsets (see Time#utc_offset). - def initialize(name, utc_offset, tzinfo = nil) + def initialize(name, utc_offset = nil, tzinfo = nil) @name = name @utc_offset = utc_offset @tzinfo = tzinfo @@ -202,8 +202,12 @@ module ActiveSupport end def utc_offset - @current_period ||= tzinfo.current_period - @current_period.utc_offset + if @utc_offset + @utc_offset + else + @current_period ||= tzinfo.current_period + @current_period.utc_offset + end end # Returns the offset of this time zone as a formatted string, of the @@ -305,71 +309,24 @@ module ActiveSupport tzinfo.period_for_local(time, dst) end - # TODO: Preload instead of lazy load for thread safety def tzinfo + @tzinfo ||= find_tzinfo + end + + # TODO: Preload instead of lazy load for thread safety + def find_tzinfo require 'tzinfo' unless defined?(::TZInfo) - @tzinfo ||= ::TZInfo::Timezone.get(MAPPING[name]) + ::TZInfo::Timezone.get(MAPPING[name]) end unless const_defined?(:ZONES) ZONES = [] ZONES_MAP = {} - [[-39_600, "International Date Line West", "Midway Island", "Samoa" ], - [-36_000, "Hawaii" ], - [-32_400, "Alaska" ], - [-28_800, "Pacific Time (US & Canada)", "Tijuana" ], - [-25_200, "Mountain Time (US & Canada)", "Chihuahua", "Mazatlan", - "Arizona" ], - [-21_600, "Central Time (US & Canada)", "Saskatchewan", "Guadalajara", - "Mexico City", "Monterrey", "Central America" ], - [-18_000, "Eastern Time (US & Canada)", "Indiana (East)", "Bogota", - "Lima", "Quito" ], - [-16_200, "Caracas" ], - [-14_400, "Atlantic Time (Canada)", "Georgetown", "La Paz", "Santiago" ], - [-12_600, "Newfoundland" ], - [-10_800, "Brasilia", "Buenos Aires", "Greenland" ], - [ -7_200, "Mid-Atlantic" ], - [ -3_600, "Azores", "Cape Verde Is." ], - [ 0, "Dublin", "Edinburgh", "Lisbon", "London", "Casablanca", - "Monrovia", "UTC" ], - [ 3_600, "Belgrade", "Bratislava", "Budapest", "Ljubljana", "Prague", - "Sarajevo", "Skopje", "Warsaw", "Zagreb", "Brussels", - "Copenhagen", "Madrid", "Paris", "Amsterdam", "Berlin", - "Bern", "Rome", "Stockholm", "Vienna", - "West Central Africa" ], - [ 7_200, "Bucharest", "Cairo", "Helsinki", "Kyiv", "Riga", "Sofia", - "Tallinn", "Vilnius", "Athens", "Istanbul", "Minsk", - "Jerusalem", "Harare", "Pretoria" ], - [ 10_800, "Moscow", "St. Petersburg", "Volgograd", "Kuwait", "Riyadh", - "Nairobi", "Baghdad" ], - [ 12_600, "Tehran" ], - [ 14_400, "Abu Dhabi", "Muscat", "Baku", "Tbilisi", "Yerevan" ], - [ 16_200, "Kabul" ], - [ 18_000, "Ekaterinburg", "Islamabad", "Karachi", "Tashkent" ], - [ 19_800, "Chennai", "Kolkata", "Mumbai", "New Delhi", "Sri Jayawardenepura" ], - [ 20_700, "Kathmandu" ], - [ 21_600, "Astana", "Dhaka", "Almaty", - "Novosibirsk" ], - [ 23_400, "Rangoon" ], - [ 25_200, "Bangkok", "Hanoi", "Jakarta", "Krasnoyarsk" ], - [ 28_800, "Beijing", "Chongqing", "Hong Kong", "Urumqi", - "Kuala Lumpur", "Singapore", "Taipei", "Perth", "Irkutsk", - "Ulaan Bataar" ], - [ 32_400, "Seoul", "Osaka", "Sapporo", "Tokyo", "Yakutsk" ], - [ 34_200, "Darwin", "Adelaide" ], - [ 36_000, "Canberra", "Melbourne", "Sydney", "Brisbane", "Hobart", - "Vladivostok", "Guam", "Port Moresby" ], - [ 39_600, "Magadan", "Solomon Is.", "New Caledonia" ], - [ 43_200, "Fiji", "Kamchatka", "Marshall Is.", "Auckland", - "Wellington" ], - [ 46_800, "Nuku'alofa" ]]. - each do |offset, *places| - places.each do |place| - place.freeze - zone = new(place, offset) - ZONES << zone - ZONES_MAP[place] = zone - end + MAPPING.each_key do |place| + place.freeze + zone = new(place) + ZONES << zone + ZONES_MAP[place] = zone end ZONES.sort! ZONES.freeze -- cgit v1.2.3 From 1b742ea9b100278dd818879a4162dab1a2c0e6d4 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 2 Apr 2010 16:44:38 -0300 Subject: delegate unknown timezones to TZInfo --- activesupport/lib/active_support/values/time_zone.rb | 17 ++++++++++++----- activesupport/test/time_zone_test.rb | 8 ++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index b9766a236a..03b324764b 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -310,13 +310,15 @@ module ActiveSupport end def tzinfo - @tzinfo ||= find_tzinfo + @tzinfo ||= TimeZone.find_tzinfo(name) end # TODO: Preload instead of lazy load for thread safety - def find_tzinfo + def self.find_tzinfo(name) require 'tzinfo' unless defined?(::TZInfo) - ::TZInfo::Timezone.get(MAPPING[name]) + ::TZInfo::Timezone.get(MAPPING[name] || name) + rescue TZInfo::InvalidTimezoneIdentifier + nil end unless const_defined?(:ZONES) @@ -330,7 +332,6 @@ module ActiveSupport end ZONES.sort! ZONES.freeze - ZONES_MAP.freeze US_ZONES = ZONES.find_all { |z| z.name =~ /US|Arizona|Indiana|Hawaii|Alaska/ } US_ZONES.freeze @@ -361,7 +362,7 @@ module ActiveSupport def [](arg) case arg when String - ZONES_MAP[arg] + ZONES_MAP[arg] ||= lookup(arg) when Numeric, ActiveSupport::Duration arg *= 3600 if arg.abs <= 13 all.find { |z| z.utc_offset == arg.to_i } @@ -375,6 +376,12 @@ module ActiveSupport def us_zones US_ZONES end + + private + + def lookup(name) + (tzinfo = find_tzinfo(name)) && create(tzinfo.name.freeze) + end end end end diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb index ce43c6507d..68027f7c94 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -75,6 +75,14 @@ class TimeZoneTest < Test::Unit::TestCase end end + def test_unknown_timezones_delegation_to_tzinfo + zone = ActiveSupport::TimeZone['America/Montevideo'] + assert_equal ActiveSupport::TimeZone, zone.class + assert_equal zone.object_id, ActiveSupport::TimeZone['America/Montevideo'].object_id + assert_equal Time.utc(2010, 1, 31, 22), zone.utc_to_local(Time.utc(2010, 2)) # daylight saving offset -0200 + assert_equal Time.utc(2010, 3, 31, 21), zone.utc_to_local(Time.utc(2010, 4)) # standard offset -0300 + end + def test_today Time.stubs(:now).returns(Time.utc(2000, 1, 1, 4, 59, 59)) # 1 sec before midnight Jan 1 EST assert_equal Date.new(1999, 12, 31), ActiveSupport::TimeZone['Eastern Time (US & Canada)'].today -- cgit v1.2.3