3 desc "Lock this application to the current gems (by unpacking them into vendor/rails)"
5 deps = %w(actionpack activerecord actionmailer activesupport activeresource)
9 rails = (version = ENV['VERSION']) ?
10 Gem.cache.find_name('rails', "= #{version}").first :
11 Gem.cache.find_name('rails').sort_by { |g| g.version }.last
13 version ||= rails.version
16 puts "No rails gem #{version} is installed. Do 'gem list rails' to see what you have available."
20 puts "Freezing to the gems for Rails #{rails.version}"
22 mkdir_p "vendor/rails"
24 chdir("vendor/rails") do
25 rails.dependencies.select { |g| deps.include? g.name }.each do |g|
26 Gem::GemRunner.new.run(["unpack", "-v", "#{g.version_requirements}", "#{g.name}"])
27 mv(Dir.glob("#{g.name}*").first, g.name)
30 Gem::GemRunner.new.run(["unpack", "-v", "=#{version}", "rails"])
31 FileUtils.mv(Dir.glob("rails*").first, "railties")
35 desc "Lock to latest Edge Rails or a specific revision with REVISION=X (ex: REVISION=4021) or a tag with TAG=Y (ex: TAG=rel_1-1-0)"
38 `svn --version` rescue nil
39 unless !$?.nil? && $?.success?
40 $stderr.puts "ERROR: Must have subversion (svn) available in the PATH to lock this application to Edge Rails"
45 mkdir_p "vendor/rails"
47 svn_root = "http://dev.rubyonrails.org/svn/rails/"
50 rails_svn = "#{svn_root}/tags/#{ENV['TAG']}"
51 touch "vendor/rails/TAG_#{ENV['TAG']}"
53 rails_svn = "#{svn_root}/trunk"
55 if ENV['REVISION'].nil?
56 ENV['REVISION'] = /^r(\d+)/.match(%x{svn -qr HEAD log #{svn_root}})[1]
57 puts "REVISION not set. Using HEAD, which is revision #{ENV['REVISION']}."
60 touch "vendor/rails/REVISION_#{ENV['REVISION']}"
63 for framework in %w(railties actionpack activerecord actionmailer activesupport activeresource)
64 system "svn export #{rails_svn}/#{framework} vendor/rails/#{framework}" + (ENV['REVISION'] ? " -r #{ENV['REVISION']}" : "")
69 desc "Unlock this application from freeze of gems or edge and return to a fluid use of system gems"
74 desc "Update both configs, scripts and public/javascripts from Rails"
75 task :update => [ "update:scripts", "update:javascripts", "update:configs" ]
78 desc "Add new scripts to the application script/ directory"
81 edge_base = "#{File.dirname(__FILE__)}/../../bin"
83 local = Dir["#{local_base}/**/*"].reject { |path| File.directory?(path) }
84 edge = Dir["#{edge_base}/**/*"].reject { |path| File.directory?(path) }
87 base_name = script[(edge_base.length+1)..-1]
88 next if base_name == "rails"
89 next if local.detect { |path| base_name == path[(local_base.length+1)..-1] }
90 if !File.directory?("#{local_base}/#{File.dirname(base_name)}")
91 mkdir_p "#{local_base}/#{File.dirname(base_name)}"
93 install script, "#{local_base}/#{base_name}", :mode => 0755
97 desc "Update your javascripts from your current rails install"
99 require 'railties_path'
100 project_dir = RAILS_ROOT + '/public/javascripts/'
101 scripts = Dir[RAILTIES_PATH + '/html/javascripts/*.js']
102 scripts.reject!{|s| File.basename(s) == 'application.js'} if File.exists?(project_dir + 'application.js')
103 FileUtils.cp(scripts, project_dir)
106 desc "Update config/boot.rb from your current rails install"
108 require 'railties_path'
109 FileUtils.cp(RAILTIES_PATH + '/environments/boot.rb', RAILS_ROOT + '/config/boot.rb')