Skip to content
Browse files

Fix tzinfo require (it broke test_raises_when_an_invalid_timezone_is_…

…defined_in_the_config in railties)
  • Loading branch information...
1 parent 4b70376 commit 3594102f3b97e5758f06a52e7bed549c85d50555 @jonleighton jonleighton committed Aug 16, 2011
Showing with 13 additions and 6 deletions.
  1. +13 −6 activesupport/lib/active_support/values/time_zone.rb
View
19 activesupport/lib/active_support/values/time_zone.rb
@@ -195,12 +195,8 @@ def self.seconds_to_utc_offset(seconds, colon = true)
# (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 = nil, tzinfo = nil)
- begin
- require 'tzinfo'
- rescue LoadError => e
- $stderr.puts "You don't have tzinfo installed in your application. Please add it to your Gemfile and run bundle install"
- raise e
- end
+ self.class.send(:require_tzinfo)
+
@name = name
@utc_offset = utc_offset
@tzinfo = tzinfo || TimeZone.find_tzinfo(name)
@@ -374,13 +370,24 @@ def us_zones
@us_zones ||= all.find_all { |z| z.name =~ /US|Arizona|Indiana|Hawaii|Alaska/ }
end
+ protected
+
+ def require_tzinfo
+ require 'tzinfo'
+ rescue LoadError
+ $stderr.puts "You don't have tzinfo installed in your application. Please add it to your Gemfile and run bundle install"
+ raise
+ end
+
private
def lookup(name)
(tzinfo = find_tzinfo(name)) && create(tzinfo.name.freeze)
end
def lazy_zones_map
+ require_tzinfo
+
@lazy_zones_map ||= Hash.new do |hash, place|
hash[place] = create(place) if MAPPING.has_key?(place)
end

0 comments on commit 3594102

Please sign in to comment.
Something went wrong with that request. Please try again.