public
Description: Miscellaneous Rake tasks and so on that I use on most projects.
Homepage:
Clone URL: git://github.com/airblade/air_blade_tools.git
air_blade_tools / tasks / air_blade_tools_tasks.rake
100644 137 lines (112 sloc) 5.069 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
namespace :rails do
  namespace :upgrade do
 
    desc 'Renames deprecated view extensions, e.g. foo.rhtml => foo.html.erb'
    task :views do
      Dir.glob('app/views/**/[^_]*.rhtml').each do |file|
        puts `svn mv #{file} #{file.gsub(/\.rhtml$/, '.html.erb')}`
      end
 
      Dir.glob('app/views/**/[^_]*.rjs').each do |file|
        puts `svn mv #{file} #{file.gsub(/\.rjs$/, '.js.rjs')}`
      end
 
      Dir.glob('app/views/**/[^_]*.rxml').each do |file|
        puts `svn mv #{file} #{file.gsub(/\.rxml$/, '.xml.builder')}`
      end
 
      Dir.glob('app/views/**/[^_]*.haml').each do |file|
        puts `svn mv #{file} #{file.gsub(/\.haml$/, '.html.haml')}`
      end
    end
 
  end
end
 
namespace :db do
 
  desc <<-END
Start a MySQL shell using the credentials in database.yml.
Sake did this but one day Sake stopped working. Strangely
Rails' databases.rake omits this task.
 
http://errtheblog.com/posts/60-sake-bomb
http://dev.rubyonrails.org/browser/trunk/railties/lib/tasks/databases.rake
END
  task :shell => :environment do
    config = ActiveRecord::Base.configurations[(RAILS_ENV or "development")]
    command = ""
    case config["adapter"]
    when "mysql" then
      (command << "mysql ")
      (command << "--host=#{(config["host"] or "localhost")} ")
      (command << "--port=#{(config["port"] or 3306)} ")
      (command << "--user=#{(config["username"] or "root")} ")
      (command << "--password=#{(config["password"] or "")} ")
      (command << config["database"])
    when "postgresql" then
      puts("You should consider switching to MySQL or get off your butt and submit a patch")
    else
      (command << "echo Unsupported database adapter: #{config["adapter"]}")
    end
    system(command)
  end
 
  namespace :fixtures do
    desc <<-END
Loads basic data into the current environment's database. Load specific fixtures using FIXTURES=x,y.
 
This differs from db:fixtures:load by loading fixtures in the db/basic_data directory rather than text/fixtures. Basic data, a.k.a. reference data, and test data serve different purposes and should not be conflated.
 
This is a better way to load basic data than within migrations because migrations are not guaranteed to run through from start to finish. The recommended way to create a new database with the current structure is via db/schema.rb. So if we cannot rely on the migrations, we should not use them to load basic data.
END
    task :basic_data => :environment do
      require 'active_record/fixtures'
      ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
      (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'db', 'basic_data', '*.{yml,csv}'))).each do |fixture_file|
        Fixtures.create_fixtures('db/basic_data', File.basename(fixture_file, '.*'))
      end
    end
  end
    
end
 
 
desc %q@
Freezes Rails to edge, or a specific revision, with symlinks etc
as described by Mike Clark (see the Cadillac section):
 
* http://svn.techno-weenie.net/projects/mephisto/trunk/lib/tasks/common.rake
* http://www.clarkware.com/cgi/blosxom/2007/01/18#ManagingVersionsWithCap
 
Add this to your Capistrano script (config/deploy.rb):
 
set :rails_version, XYZ unless variables[:rails_version]
task :after_update_code, :roles => :app do
run <<-CMD
cd #{release_path} &&
rake deploy_edge REVISION=#{rails_version} RAILS_PATH=/var/www/apps/rails
CMD
end
@
namespace 'deploy' do
  task :edge do
    ENV['SHARED_PATH'] = '../../shared' unless ENV['SHARED_PATH']
    ENV['RAILS_PATH'] ||= File.join(ENV['SHARED_PATH'], 'rails')
    ENV['REPO_BRANCH'] ||= 'trunk'
    
    checkout_path = File.join(ENV['RAILS_PATH'], 'trunk')
    export_path = "#{ENV['RAILS_PATH']}/rev_#{ENV['REVISION']}"
    symlink_path = 'vendor/rails'
 
    # do we need to checkout the file?
    unless File.exists?(checkout_path)
      puts 'setting up rails trunk'
      get_framework_for checkout_path do |framework|
        system "svn co http://dev.rubyonrails.org/svn/rails/#{ENV['REPO_BRANCH']}/#{framework}/lib #{checkout_path}/#{framework}/lib --quiet"
      end
    end
 
    # do we need to export the revision?
    unless File.exists?(export_path)
      puts "setting up rails rev #{ENV['REVISION']}"
      get_framework_for export_path do |framework|
        system "svn up #{checkout_path}/#{framework}/lib -r #{ENV['REVISION']} --quiet"
        system "svn export #{checkout_path}/#{framework}/lib #{export_path}/#{framework}/lib"
      end
    end
 
    puts 'linking rails'
    rm_rf symlink_path
    mkdir_p symlink_path
 
    get_framework_for symlink_path do |framework|
      ln_s File.expand_path("#{export_path}/#{framework}/lib"), "#{symlink_path}/#{framework}/lib"
    end
    
    touch "vendor/rails_#{ENV['REVISION']}"
  end
 
  def get_framework_for(*paths)
    %w( railties actionpack activerecord actionmailer activesupport activeresource actionwebservice ).each do |framework|
      paths.each { |path| mkdir_p "#{path}/#{framework}" }
      yield framework
    end
  end
end