From 36662ed08e2ed5d71cc21409a87aec8ebbf9a4b6 Mon Sep 17 00:00:00 2001
From: Joshua Peek <josh@joshpeek.com>
Date: Sun, 4 May 2008 21:11:03 -0500
Subject: Replaced unnecessary class variable with a constant in whiny nil.

---
 activesupport/lib/active_support/whiny_nil.rb | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

(limited to 'activesupport')

diff --git a/activesupport/lib/active_support/whiny_nil.rb b/activesupport/lib/active_support/whiny_nil.rb
index 099619191c..36fe9510ba 100644
--- a/activesupport/lib/active_support/whiny_nil.rb
+++ b/activesupport/lib/active_support/whiny_nil.rb
@@ -28,12 +28,12 @@ class NilClass
   WHINERS = [::Array]
   WHINERS << ::ActiveRecord::Base if defined? ::ActiveRecord
 
-  @@method_class_map = Hash.new
+  METHOD_CLASS_MAP = Hash.new
 
   WHINERS.each do |klass|
     methods = klass.public_instance_methods - public_instance_methods
     class_name = klass.name
-    methods.each { |method| @@method_class_map[method.to_sym] = class_name }
+    methods.each { |method| METHOD_CLASS_MAP[method.to_sym] = class_name }
   end
 
   # Raises a RuntimeError when you attempt to call +id+ on +nil+.
@@ -43,7 +43,7 @@ class NilClass
 
   private
     def method_missing(method, *args, &block)
-      raise_nil_warning_for @@method_class_map[method], method, caller
+      raise_nil_warning_for METHOD_CLASS_MAP[method], method, caller
     end
 
     # Raises a NoMethodError when you attempt to call a method on +nil+.
-- 
cgit v1.2.3


From a40223d36d4e90d520b09d51a3f2a7b3cd6c2f07 Mon Sep 17 00:00:00 2001
From: Joshua Peek <josh@joshpeek.com>
Date: Sun, 4 May 2008 21:53:07 -0500
Subject: Preload TimeZone zones for thread safety.

---
 .../lib/active_support/values/time_zone.rb         | 439 +++++++++++----------
 1 file changed, 222 insertions(+), 217 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 80057fe832..9cdc2a74ed 100644
--- a/activesupport/lib/active_support/values/time_zone.rb
+++ b/activesupport/lib/active_support/values/time_zone.rb
@@ -1,149 +1,152 @@
 class TimeZone
-  # Keys are Rails TimeZone names, values are TZInfo identifiers
-  MAPPING = {
-    "International Date Line West" => "Pacific/Midway",
-    "Midway Island"                => "Pacific/Midway",
-    "Samoa"                        => "Pacific/Pago_Pago",
-    "Hawaii"                       => "Pacific/Honolulu",
-    "Alaska"                       => "America/Juneau",
-    "Pacific Time (US & Canada)"   => "America/Los_Angeles",
-    "Tijuana"                      => "America/Tijuana",
-    "Mountain Time (US & Canada)"  => "America/Denver",
-    "Arizona"                      => "America/Phoenix",
-    "Chihuahua"                    => "America/Chihuahua",
-    "Mazatlan"                     => "America/Mazatlan",
-    "Central Time (US & Canada)"   => "America/Chicago",
-    "Saskatchewan"                 => "America/Regina",
-    "Guadalajara"                  => "America/Mexico_City",
-    "Mexico City"                  => "America/Mexico_City",
-    "Monterrey"                    => "America/Monterrey",
-    "Central America"              => "America/Guatemala",
-    "Eastern Time (US & Canada)"   => "America/New_York",
-    "Indiana (East)"               => "America/Indiana/Indianapolis",
-    "Bogota"                       => "America/Bogota",
-    "Lima"                         => "America/Lima",
-    "Quito"                        => "America/Lima",
-    "Atlantic Time (Canada)"       => "America/Halifax",
-    "Caracas"                      => "America/Caracas",
-    "La Paz"                       => "America/La_Paz",
-    "Santiago"                     => "America/Santiago",
-    "Newfoundland"                 => "America/St_Johns",
-    "Brasilia"                     => "America/Argentina/Buenos_Aires",
-    "Buenos Aires"                 => "America/Argentina/Buenos_Aires",
-    "Georgetown"                   => "America/Argentina/San_Juan",
-    "Greenland"                    => "America/Godthab",
-    "Mid-Atlantic"                 => "Atlantic/South_Georgia",
-    "Azores"                       => "Atlantic/Azores",
-    "Cape Verde Is."               => "Atlantic/Cape_Verde",
-    "Dublin"                       => "Europe/Dublin",
-    "Edinburgh"                    => "Europe/Dublin",
-    "Lisbon"                       => "Europe/Lisbon",
-    "London"                       => "Europe/London",
-    "Casablanca"                   => "Africa/Casablanca",
-    "Monrovia"                     => "Africa/Monrovia",
-    "UTC"                          => "Etc/UTC",
-    "Belgrade"                     => "Europe/Belgrade",
-    "Bratislava"                   => "Europe/Bratislava",
-    "Budapest"                     => "Europe/Budapest",
-    "Ljubljana"                    => "Europe/Ljubljana",
-    "Prague"                       => "Europe/Prague",
-    "Sarajevo"                     => "Europe/Sarajevo",
-    "Skopje"                       => "Europe/Skopje",
-    "Warsaw"                       => "Europe/Warsaw",
-    "Zagreb"                       => "Europe/Zagreb",
-    "Brussels"                     => "Europe/Brussels",
-    "Copenhagen"                   => "Europe/Copenhagen",
-    "Madrid"                       => "Europe/Madrid",
-    "Paris"                        => "Europe/Paris",
-    "Amsterdam"                    => "Europe/Amsterdam",
-    "Berlin"                       => "Europe/Berlin",
-    "Bern"                         => "Europe/Berlin",
-    "Rome"                         => "Europe/Rome",
-    "Stockholm"                    => "Europe/Stockholm",
-    "Vienna"                       => "Europe/Vienna",
-    "West Central Africa"          => "Africa/Algiers",
-    "Bucharest"                    => "Europe/Bucharest",
-    "Cairo"                        => "Africa/Cairo",
-    "Helsinki"                     => "Europe/Helsinki",
-    "Kyev"                         => "Europe/Kiev",
-    "Riga"                         => "Europe/Riga",
-    "Sofia"                        => "Europe/Sofia",
-    "Tallinn"                      => "Europe/Tallinn",
-    "Vilnius"                      => "Europe/Vilnius",
-    "Athens"                       => "Europe/Athens",
-    "Istanbul"                     => "Europe/Istanbul",
-    "Minsk"                        => "Europe/Minsk",
-    "Jerusalem"                    => "Asia/Jerusalem",
-    "Harare"                       => "Africa/Harare",
-    "Pretoria"                     => "Africa/Johannesburg",
-    "Moscow"                       => "Europe/Moscow",
-    "St. Petersburg"               => "Europe/Moscow",
-    "Volgograd"                    => "Europe/Moscow",
-    "Kuwait"                       => "Asia/Kuwait",
-    "Riyadh"                       => "Asia/Riyadh",
-    "Nairobi"                      => "Africa/Nairobi",
-    "Baghdad"                      => "Asia/Baghdad",
-    "Tehran"                       => "Asia/Tehran",
-    "Abu Dhabi"                    => "Asia/Muscat",
-    "Muscat"                       => "Asia/Muscat",
-    "Baku"                         => "Asia/Baku",
-    "Tbilisi"                      => "Asia/Tbilisi",
-    "Yerevan"                      => "Asia/Yerevan",
-    "Kabul"                        => "Asia/Kabul",
-    "Ekaterinburg"                 => "Asia/Yekaterinburg",
-    "Islamabad"                    => "Asia/Karachi",
-    "Karachi"                      => "Asia/Karachi",
-    "Tashkent"                     => "Asia/Tashkent",
-    "Chennai"                      => "Asia/Kolkata",
-    "Kolkata"                      => "Asia/Kolkata",
-    "Mumbai"                       => "Asia/Kolkata",
-    "New Delhi"                    => "Asia/Kolkata",
-    "Kathmandu"                    => "Asia/Katmandu",
-    "Astana"                       => "Asia/Dhaka",
-    "Dhaka"                        => "Asia/Dhaka",
-    "Sri Jayawardenepura"          => "Asia/Dhaka",
-    "Almaty"                       => "Asia/Almaty",
-    "Novosibirsk"                  => "Asia/Novosibirsk",
-    "Rangoon"                      => "Asia/Rangoon",
-    "Bangkok"                      => "Asia/Bangkok",
-    "Hanoi"                        => "Asia/Bangkok",
-    "Jakarta"                      => "Asia/Jakarta",
-    "Krasnoyarsk"                  => "Asia/Krasnoyarsk",
-    "Beijing"                      => "Asia/Shanghai",
-    "Chongqing"                    => "Asia/Chongqing",
-    "Hong Kong"                    => "Asia/Hong_Kong",
-    "Urumqi"                       => "Asia/Urumqi",
-    "Kuala Lumpur"                 => "Asia/Kuala_Lumpur",
-    "Singapore"                    => "Asia/Singapore",
-    "Taipei"                       => "Asia/Taipei",
-    "Perth"                        => "Australia/Perth",
-    "Irkutsk"                      => "Asia/Irkutsk",
-    "Ulaan Bataar"                 => "Asia/Ulaanbaatar",
-    "Seoul"                        => "Asia/Seoul",
-    "Osaka"                        => "Asia/Tokyo",
-    "Sapporo"                      => "Asia/Tokyo",
-    "Tokyo"                        => "Asia/Tokyo",
-    "Yakutsk"                      => "Asia/Yakutsk",
-    "Darwin"                       => "Australia/Darwin",
-    "Adelaide"                     => "Australia/Adelaide",
-    "Canberra"                     => "Australia/Melbourne",
-    "Melbourne"                    => "Australia/Melbourne",
-    "Sydney"                       => "Australia/Sydney",
-    "Brisbane"                     => "Australia/Brisbane",
-    "Hobart"                       => "Australia/Hobart",
-    "Vladivostok"                  => "Asia/Vladivostok",
-    "Guam"                         => "Pacific/Guam",
-    "Port Moresby"                 => "Pacific/Port_Moresby",
-    "Magadan"                      => "Asia/Magadan",
-    "Solomon Is."                  => "Asia/Magadan",
-    "New Caledonia"                => "Pacific/Noumea",
-    "Fiji"                         => "Pacific/Fiji",
-    "Kamchatka"                    => "Asia/Kamchatka",
-    "Marshall Is."                 => "Pacific/Majuro",
-    "Auckland"                     => "Pacific/Auckland",
-    "Wellington"                   => "Pacific/Auckland",
-    "Nuku'alofa"                   => "Pacific/Tongatapu"
-  }
+  unless const_defined?(:MAPPING)
+    # Keys are Rails TimeZone names, values are TZInfo identifiers
+    MAPPING = {
+      "International Date Line West" => "Pacific/Midway",
+      "Midway Island"                => "Pacific/Midway",
+      "Samoa"                        => "Pacific/Pago_Pago",
+      "Hawaii"                       => "Pacific/Honolulu",
+      "Alaska"                       => "America/Juneau",
+      "Pacific Time (US & Canada)"   => "America/Los_Angeles",
+      "Tijuana"                      => "America/Tijuana",
+      "Mountain Time (US & Canada)"  => "America/Denver",
+      "Arizona"                      => "America/Phoenix",
+      "Chihuahua"                    => "America/Chihuahua",
+      "Mazatlan"                     => "America/Mazatlan",
+      "Central Time (US & Canada)"   => "America/Chicago",
+      "Saskatchewan"                 => "America/Regina",
+      "Guadalajara"                  => "America/Mexico_City",
+      "Mexico City"                  => "America/Mexico_City",
+      "Monterrey"                    => "America/Monterrey",
+      "Central America"              => "America/Guatemala",
+      "Eastern Time (US & Canada)"   => "America/New_York",
+      "Indiana (East)"               => "America/Indiana/Indianapolis",
+      "Bogota"                       => "America/Bogota",
+      "Lima"                         => "America/Lima",
+      "Quito"                        => "America/Lima",
+      "Atlantic Time (Canada)"       => "America/Halifax",
+      "Caracas"                      => "America/Caracas",
+      "La Paz"                       => "America/La_Paz",
+      "Santiago"                     => "America/Santiago",
+      "Newfoundland"                 => "America/St_Johns",
+      "Brasilia"                     => "America/Argentina/Buenos_Aires",
+      "Buenos Aires"                 => "America/Argentina/Buenos_Aires",
+      "Georgetown"                   => "America/Argentina/San_Juan",
+      "Greenland"                    => "America/Godthab",
+      "Mid-Atlantic"                 => "Atlantic/South_Georgia",
+      "Azores"                       => "Atlantic/Azores",
+      "Cape Verde Is."               => "Atlantic/Cape_Verde",
+      "Dublin"                       => "Europe/Dublin",
+      "Edinburgh"                    => "Europe/Dublin",
+      "Lisbon"                       => "Europe/Lisbon",
+      "London"                       => "Europe/London",
+      "Casablanca"                   => "Africa/Casablanca",
+      "Monrovia"                     => "Africa/Monrovia",
+      "UTC"                          => "Etc/UTC",
+      "Belgrade"                     => "Europe/Belgrade",
+      "Bratislava"                   => "Europe/Bratislava",
+      "Budapest"                     => "Europe/Budapest",
+      "Ljubljana"                    => "Europe/Ljubljana",
+      "Prague"                       => "Europe/Prague",
+      "Sarajevo"                     => "Europe/Sarajevo",
+      "Skopje"                       => "Europe/Skopje",
+      "Warsaw"                       => "Europe/Warsaw",
+      "Zagreb"                       => "Europe/Zagreb",
+      "Brussels"                     => "Europe/Brussels",
+      "Copenhagen"                   => "Europe/Copenhagen",
+      "Madrid"                       => "Europe/Madrid",
+      "Paris"                        => "Europe/Paris",
+      "Amsterdam"                    => "Europe/Amsterdam",
+      "Berlin"                       => "Europe/Berlin",
+      "Bern"                         => "Europe/Berlin",
+      "Rome"                         => "Europe/Rome",
+      "Stockholm"                    => "Europe/Stockholm",
+      "Vienna"                       => "Europe/Vienna",
+      "West Central Africa"          => "Africa/Algiers",
+      "Bucharest"                    => "Europe/Bucharest",
+      "Cairo"                        => "Africa/Cairo",
+      "Helsinki"                     => "Europe/Helsinki",
+      "Kyev"                         => "Europe/Kiev",
+      "Riga"                         => "Europe/Riga",
+      "Sofia"                        => "Europe/Sofia",
+      "Tallinn"                      => "Europe/Tallinn",
+      "Vilnius"                      => "Europe/Vilnius",
+      "Athens"                       => "Europe/Athens",
+      "Istanbul"                     => "Europe/Istanbul",
+      "Minsk"                        => "Europe/Minsk",
+      "Jerusalem"                    => "Asia/Jerusalem",
+      "Harare"                       => "Africa/Harare",
+      "Pretoria"                     => "Africa/Johannesburg",
+      "Moscow"                       => "Europe/Moscow",
+      "St. Petersburg"               => "Europe/Moscow",
+      "Volgograd"                    => "Europe/Moscow",
+      "Kuwait"                       => "Asia/Kuwait",
+      "Riyadh"                       => "Asia/Riyadh",
+      "Nairobi"                      => "Africa/Nairobi",
+      "Baghdad"                      => "Asia/Baghdad",
+      "Tehran"                       => "Asia/Tehran",
+      "Abu Dhabi"                    => "Asia/Muscat",
+      "Muscat"                       => "Asia/Muscat",
+      "Baku"                         => "Asia/Baku",
+      "Tbilisi"                      => "Asia/Tbilisi",
+      "Yerevan"                      => "Asia/Yerevan",
+      "Kabul"                        => "Asia/Kabul",
+      "Ekaterinburg"                 => "Asia/Yekaterinburg",
+      "Islamabad"                    => "Asia/Karachi",
+      "Karachi"                      => "Asia/Karachi",
+      "Tashkent"                     => "Asia/Tashkent",
+      "Chennai"                      => "Asia/Kolkata",
+      "Kolkata"                      => "Asia/Kolkata",
+      "Mumbai"                       => "Asia/Kolkata",
+      "New Delhi"                    => "Asia/Kolkata",
+      "Kathmandu"                    => "Asia/Katmandu",
+      "Astana"                       => "Asia/Dhaka",
+      "Dhaka"                        => "Asia/Dhaka",
+      "Sri Jayawardenepura"          => "Asia/Dhaka",
+      "Almaty"                       => "Asia/Almaty",
+      "Novosibirsk"                  => "Asia/Novosibirsk",
+      "Rangoon"                      => "Asia/Rangoon",
+      "Bangkok"                      => "Asia/Bangkok",
+      "Hanoi"                        => "Asia/Bangkok",
+      "Jakarta"                      => "Asia/Jakarta",
+      "Krasnoyarsk"                  => "Asia/Krasnoyarsk",
+      "Beijing"                      => "Asia/Shanghai",
+      "Chongqing"                    => "Asia/Chongqing",
+      "Hong Kong"                    => "Asia/Hong_Kong",
+      "Urumqi"                       => "Asia/Urumqi",
+      "Kuala Lumpur"                 => "Asia/Kuala_Lumpur",
+      "Singapore"                    => "Asia/Singapore",
+      "Taipei"                       => "Asia/Taipei",
+      "Perth"                        => "Australia/Perth",
+      "Irkutsk"                      => "Asia/Irkutsk",
+      "Ulaan Bataar"                 => "Asia/Ulaanbaatar",
+      "Seoul"                        => "Asia/Seoul",
+      "Osaka"                        => "Asia/Tokyo",
+      "Sapporo"                      => "Asia/Tokyo",
+      "Tokyo"                        => "Asia/Tokyo",
+      "Yakutsk"                      => "Asia/Yakutsk",
+      "Darwin"                       => "Australia/Darwin",
+      "Adelaide"                     => "Australia/Adelaide",
+      "Canberra"                     => "Australia/Melbourne",
+      "Melbourne"                    => "Australia/Melbourne",
+      "Sydney"                       => "Australia/Sydney",
+      "Brisbane"                     => "Australia/Brisbane",
+      "Hobart"                       => "Australia/Hobart",
+      "Vladivostok"                  => "Asia/Vladivostok",
+      "Guam"                         => "Pacific/Guam",
+      "Port Moresby"                 => "Pacific/Port_Moresby",
+      "Magadan"                      => "Asia/Magadan",
+      "Solomon Is."                  => "Asia/Magadan",
+      "New Caledonia"                => "Pacific/Noumea",
+      "Fiji"                         => "Pacific/Fiji",
+      "Kamchatka"                    => "Asia/Kamchatka",
+      "Marshall Is."                 => "Pacific/Majuro",
+      "Auckland"                     => "Pacific/Auckland",
+      "Wellington"                   => "Pacific/Auckland",
+      "Nuku'alofa"                   => "Pacific/Tongatapu"
+    }.each { |name, zone| name.freeze; zone.freeze }
+    MAPPING.freeze
+  end
 
   include Comparable
   attr_reader :name
@@ -157,7 +160,7 @@ class TimeZone
     @utc_offset = utc_offset
     @tzinfo = tzinfo
   end
-  
+
   def utc_offset
     @utc_offset ||= tzinfo.current_period.utc_offset
   end
@@ -180,7 +183,7 @@ class TimeZone
   def to_s
     "(UTC#{formatted_offset}) #{name}"
   end
-    
+
   # Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from given values. Example:
   #
   #   Time.zone = "Hawaii"                      # => "Hawaii"
@@ -199,7 +202,7 @@ class TimeZone
     utc = Time.at(secs).utc rescue DateTime.civil(1970).since(secs)
     utc.in_time_zone(self)
   end
-  
+
   # Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from parsed string. Example:
   #
   #   Time.zone = "Hawaii"                      # => "Hawaii"
@@ -213,7 +216,7 @@ class TimeZone
     time = Time.parse(str, now) rescue DateTime.parse(str)
     ActiveSupport::TimeWithZone.new(nil, self, time)
   end
-  
+
   # Returns an ActiveSupport::TimeWithZone instance representing the current time
   # in the time zone represented by +self+. Example:
   #
@@ -228,12 +231,12 @@ class TimeZone
     tzinfo.now.to_date
   end
 
-  # Adjust the given time to the simultaneous time in the time zone represented by +self+. Returns a 
+  # Adjust the given time to the simultaneous time in the time zone represented by +self+. Returns a
   # Time.utc() instance -- if you want an ActiveSupport::TimeWithZone instance, use Time#in_time_zone() instead.
   def utc_to_local(time)
     tzinfo.utc_to_local(time)
   end
-  
+
   # Adjust the given time to the simultaneous time in UTC. Returns a Time.utc() instance.
   def local_to_utc(time, dst=true)
     tzinfo.local_to_utc(time, dst)
@@ -248,12 +251,75 @@ class TimeZone
   def period_for_local(time, dst=true)
     tzinfo.period_for_local(time, dst)
   end
-  
+
+  # TODO: Preload instead of lazy load for thread safety
   def tzinfo
     @tzinfo ||= TZInfo::Timezone.get(MAPPING[name])
   end
 
-  @@zones = nil
+  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" ],
+     [-14_400, "Atlantic Time (Canada)", "Caracas", "La Paz", "Santiago" ],
+     [-12_600, "Newfoundland" ],
+     [-10_800, "Brasilia", "Buenos Aires", "Georgetown", "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", "Kyev", "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" ],
+     [ 20_700, "Kathmandu" ],
+     [ 21_600, "Astana", "Dhaka", "Sri Jayawardenepura", "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
+    end
+    ZONES.sort!
+    ZONES.freeze
+    ZONES_MAP.freeze
+  end
 
   class << self
     alias_method :create, :new
@@ -269,67 +335,7 @@ class TimeZone
     # TimeZone objects per time zone, in many cases, to make it easier
     # for users to find their own time zone.
     def all
-      unless @@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" ],
-         [-14_400, "Atlantic Time (Canada)", "Caracas", "La Paz", "Santiago" ],
-         [-12_600, "Newfoundland" ],
-         [-10_800, "Brasilia", "Buenos Aires", "Georgetown", "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", "Kyev", "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" ],
-         [ 20_700, "Kathmandu" ],
-         [ 21_600, "Astana", "Dhaka", "Sri Jayawardenepura", "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|
-            zone = create(place, offset)
-            @@zones << zone
-            @@zones_map[place] = zone
-          end
-        end
-        @@zones.sort!
-      end
-      @@zones
+      ZONES
     end
 
     # Locate a specific time zone object. If the argument is a string, it
@@ -340,8 +346,7 @@ class TimeZone
     def [](arg)
       case arg
         when String
-          all # force the zones to be loaded
-          @@zones_map[arg]
+          ZONES_MAP[arg]
         when Numeric, ActiveSupport::Duration
           arg *= 3600 if arg.abs <= 13
           all.find { |z| z.utc_offset == arg.to_i }
@@ -352,7 +357,7 @@ class TimeZone
 
     # A regular expression that matches the names of all time zones in
     # the USA.
-    US_ZONES = /US|Arizona|Indiana|Hawaii|Alaska/
+    US_ZONES = /US|Arizona|Indiana|Hawaii|Alaska/.freeze
 
     # A convenience method for returning a collection of TimeZone objects
     # for time zones in the USA.
-- 
cgit v1.2.3


From d75525b045b9f27ed108912a6dbdbad5ab775045 Mon Sep 17 00:00:00 2001
From: Sean Ouimet <sean@seanouimet.com>
Date: Mon, 5 May 2008 10:03:11 -0500
Subject: Added OrderedHash#delete [#113 state:resolved] Signed-off-by: Joshua
 Peek <josh@joshpeek.com>

---
 activesupport/lib/active_support/ordered_options.rb |  6 ++++++
 activesupport/test/ordered_options_test.rb          | 13 +++++++++++++
 2 files changed, 19 insertions(+)

(limited to 'activesupport')

diff --git a/activesupport/lib/active_support/ordered_options.rb b/activesupport/lib/active_support/ordered_options.rb
index b2b1b0e438..3172f62f0d 100644
--- a/activesupport/lib/active_support/ordered_options.rb
+++ b/activesupport/lib/active_support/ordered_options.rb
@@ -18,6 +18,12 @@ module ActiveSupport
         pair = assoc(key)
         pair ? pair.last : nil
       end
+      
+      def delete(key)
+        pair = assoc(key)
+        pair ? array_index = index(pair) : nil
+        array_index ? delete_at(array_index).last : nil
+      end
 
       def keys
         collect { |key, value| key }
diff --git a/activesupport/test/ordered_options_test.rb b/activesupport/test/ordered_options_test.rb
index 1a1d0c7648..3d537a0ae4 100644
--- a/activesupport/test/ordered_options_test.rb
+++ b/activesupport/test/ordered_options_test.rb
@@ -29,6 +29,19 @@ class OrderedHashTest < Test::Unit::TestCase
     assert_equal value, @ordered_hash.values.last
     assert_equal value, @ordered_hash[key]
   end
+  
+  def test_delete
+    key, value = 'white', 'ffffff'
+    bad_key = 'black'
+    
+    @ordered_hash[key] = value
+    assert_equal @keys.length + 1, @ordered_hash.length
+    
+    assert_equal value, @ordered_hash.delete(key)
+    assert_equal @keys.length, @ordered_hash.length
+    
+    assert_nil @ordered_hash.delete(bad_key)
+  end
 end
 
 class OrderedOptionsTest < Test::Unit::TestCase
-- 
cgit v1.2.3


From 3cffe92ff066c2b35eef409547db93652c5cccfc Mon Sep 17 00:00:00 2001
From: Joshua Peek <josh@joshpeek.com>
Date: Mon, 5 May 2008 10:22:29 -0500
Subject: Added Ruby 1.8 implementation of Process.daemon

---
 activesupport/CHANGELOG                            |  2 ++
 .../active_support/core_ext/kernel/daemonizing.rb  | 12 ++---------
 .../lib/active_support/core_ext/process.rb         |  1 +
 .../lib/active_support/core_ext/process/daemon.rb  | 25 ++++++++++++++++++++++
 4 files changed, 30 insertions(+), 10 deletions(-)
 create mode 100644 activesupport/lib/active_support/core_ext/process.rb
 create mode 100644 activesupport/lib/active_support/core_ext/process/daemon.rb

(limited to 'activesupport')

diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index a911361d3b..3ee9ed925c 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
 *SVN*
 
+* Added Ruby 1.8 implementation of Process.daemon
+
 * Duration #since and #ago with no argument (e.g., 5.days.ago) return TimeWithZone when config.time_zone is set. Introducing Time.current, which returns Time.zone.now if config.time_zone is set, otherwise just returns Time.now [Geoff Buesing]
 
 * Time#since behaves correctly when passed a Duration. Closes #11527 [kemiller]
diff --git a/activesupport/lib/active_support/core_ext/kernel/daemonizing.rb b/activesupport/lib/active_support/core_ext/kernel/daemonizing.rb
index 0e78819fdf..ed9d1f9bf2 100644
--- a/activesupport/lib/active_support/core_ext/kernel/daemonizing.rb
+++ b/activesupport/lib/active_support/core_ext/kernel/daemonizing.rb
@@ -2,14 +2,6 @@ module Kernel
   # Turns the current script into a daemon process that detaches from the console.
   # It can be shut down with a TERM signal.
   def daemonize
-    exit if fork                   # Parent exits, child continues.
-    Process.setsid                 # Become session leader.
-    exit if fork                   # Zap session leader. See [1].
-    Dir.chdir "/"                  # Release old working directory.
-    File.umask 0000                # Ensure sensible umask. Adjust as needed.
-    STDIN.reopen "/dev/null"       # Free file descriptors and
-    STDOUT.reopen "/dev/null", "a" # point them somewhere sensible.
-    STDERR.reopen STDOUT           # STDOUT/ERR should better go to a logfile.
-    trap("TERM") { exit }
+    Process.daemon
   end
-end
\ No newline at end of file
+end
diff --git a/activesupport/lib/active_support/core_ext/process.rb b/activesupport/lib/active_support/core_ext/process.rb
new file mode 100644
index 0000000000..0b0bc6dc69
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/process.rb
@@ -0,0 +1 @@
+require 'active_support/core_ext/process/daemon'
diff --git a/activesupport/lib/active_support/core_ext/process/daemon.rb b/activesupport/lib/active_support/core_ext/process/daemon.rb
new file mode 100644
index 0000000000..95ad5f8a5d
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/process/daemon.rb
@@ -0,0 +1,25 @@
+if RUBY_VERSION < "1.9"
+  module Process
+    def self.daemon(nochdir = nil, noclose = nil)
+      exit if fork                     # Parent exits, child continues.
+      Process.setsid                   # Become session leader.
+      exit if fork                     # Zap session leader. See [1].
+
+      unless nochdir
+        Dir.chdir "/"                  # Release old working directory.
+      end
+
+      File.umask 0000                  # Ensure sensible umask. Adjust as needed.
+
+      unless noclose
+        STDIN.reopen "/dev/null"       # Free file descriptors and
+        STDOUT.reopen "/dev/null", "a" # point them somewhere sensible.
+        STDERR.reopen '/dev/null', 'a'
+      end
+
+      trap("TERM") { exit }
+
+      return 0
+    end
+  end
+end
-- 
cgit v1.2.3