aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/Rakefile
diff options
context:
space:
mode:
authorGeoff Buesing <gbuesing@gmail.com>2008-03-30 22:24:35 +0000
committerGeoff Buesing <gbuesing@gmail.com>2008-03-30 22:24:35 +0000
commitd4493bc562f4f774bfad075e2ba57be3434046c3 (patch)
tree520394021f0433e164b02b49b9c39efa35442110 /activesupport/Rakefile
parentc2ce69860a01205a68dce1d642a02da5595094b6 (diff)
downloadrails-d4493bc562f4f774bfad075e2ba57be3434046c3.tar.gz
rails-d4493bc562f4f774bfad075e2ba57be3434046c3.tar.bz2
rails-d4493bc562f4f774bfad075e2ba57be3434046c3.zip
Bundling abbreviated version of TZInfo gem 0.3.8: only the classes and zone definitions required to support Rails time zone features are included. If a recent version of the full TZInfo gem is installed, this will take precedence over the bundled version
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9149 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/Rakefile')
-rw-r--r--activesupport/Rakefile88
1 files changed, 88 insertions, 0 deletions
diff --git a/activesupport/Rakefile b/activesupport/Rakefile
index a6121ba072..c108d5e57a 100644
--- a/activesupport/Rakefile
+++ b/activesupport/Rakefile
@@ -85,3 +85,91 @@ task :release => [ :package ] do
rubyforge.login
rubyforge.add_release(PKG_NAME, PKG_NAME, "REL #{PKG_VERSION}", *packages)
end
+
+
+require 'lib/active_support/values/time_zone'
+
+namespace :tzinfo do
+ desc "Update bundled tzinfo gem. Only copies the subset of classes and definitions required to support Rails time zone features."
+ task :update => ['tzinfo:copy_classes', 'tzinfo:copy_definitions'] do
+ Rake::Task['tzinfo:cleanup_tmp'].invoke
+ end
+
+ task :unpack_gem do
+ mkdir_p "tmp"
+ cd "tmp"
+ sh "gem unpack --version #{ENV['VERSION'] || "'> 0'"} tzinfo"
+ cd ".."
+ end
+
+ task :copy_classes => :unpack_gem do
+ mkdir_p "#{destination_path}/tzinfo"
+ cp "#{tmp_path}/lib/tzinfo.rb", destination_path
+ comment_requires_for_excluded_classes!('tzinfo.rb')
+ files = FileList["#{tmp_path}/lib/tzinfo/*.rb"]
+ files.each do |file|
+ filename = File.basename(file)
+ unless excluded_classes.include? filename.sub(/.rb$/, '')
+ cp "#{tmp_path}/lib/tzinfo/#{filename}", "#{destination_path}/tzinfo"
+ comment_requires_for_excluded_classes!("tzinfo/#{filename}")
+ end
+ end
+ end
+
+ task :copy_definitions => :unpack_gem do
+ definitions_path = "#{destination_path}/tzinfo/definitions/"
+ mkdir_p definitions_path
+ TimeZone::MAPPING.values.each do |zone|
+ subdir = nil
+ if /\// === zone
+ subdir = zone.sub(/\w+$/, '')
+ mkdir_p "#{definitions_path}/#{subdir}"
+ end
+ cp "#{tmp_path}/lib/tzinfo/definitions/#{zone}.rb", "#{definitions_path}/#{subdir}"
+ end
+ end
+
+ task :cleanup_tmp do
+ rm_rf "tmp"
+ end
+
+ def comment_requires_for_excluded_classes!(file)
+ lines = open("#{destination_path}/#{file}") {|f| f.readlines}
+ updated = false
+
+ new_lines = []
+ lines.each do |line|
+ if Regexp.new("require 'tzinfo/(#{excluded_classes.join('|')})'") === line
+ updated = true
+ new_lines << "# #{line}"
+ else
+ new_lines << line
+ end
+ end
+
+ if updated
+ open("#{destination_path}/#{file}", "w") {|f| f.write(new_lines.join)}
+ end
+ end
+
+ def version
+ ENV['VERSION'] ||= get_unpacked_version
+ end
+
+ def get_unpacked_version
+ m = (FileList["tmp/tzinfo-*"].to_s.match /\d+\.\d+\.\d+/)
+ m ? m[0] : raise(LoadError, "TZInfo gem must be installed locally. `gem install tzinfo` and try again")
+ end
+
+ def tmp_path
+ "tmp/tzinfo-#{version}"
+ end
+
+ def destination_path
+ "lib/active_support/vendor/tzinfo-#{version}"
+ end
+
+ def excluded_classes
+ %w(country country_index_definition country_info country_timezone tzdataparser)
+ end
+end \ No newline at end of file