Created
January 26, 2010 09:42
-
-
Save rwoeber/286712 to your computer and use it in GitHub Desktop.
rake tasks to help migrating from rails 1.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# by courtesy of | |
# - http://www.slashdotdash.net/2007/12/03/rails-2-upgrade-notes/ | |
# - http://marklunds.com/articles/one/409 | |
MOVE_COMMAND = "git mv" | |
desc "Checks your app and gently warns you if you are using deprecated code." | |
task :deprecated => :environment do | |
deprecated = { | |
'@params' => 'Use params[] instead', | |
'@session' => 'Use session[] instead', | |
'@flash' => 'Use flash[] instead', | |
'@request' => 'Use request[] instead', | |
'@env' => 'Use env[] instead', | |
'find_all' => 'Use find(:all) instead', | |
'find_first' => 'Use find(:first) instead', | |
'render_partial' => 'Use render :partial instead', | |
'component' => 'Use of components are frowned upon', | |
'paginate' => 'The default paginator is slow. Writing your own may be faster', | |
'start_form_tag' => 'Use form_for instead', | |
'end_form_tag' => 'Use form_for instead', | |
':post => true' => 'Use :method => :post instead' | |
} | |
deprecated.each do |key, warning| | |
puts '--> ' + key | |
output = `cd '#{File.expand_path('app', RAILS_ROOT)}' && grep -n --exclude=*.svn* -r '#{key}' *` | |
unless output =~ /^$/ | |
puts " !! " + warning + " !!" | |
puts ' ' + '.' * (warning.length + 6) | |
puts output | |
else | |
puts " Clean! Cheers for you!" | |
end | |
puts | |
end | |
end | |
namespace 'views' do | |
desc 'Renames all .rhtml views to .html.erb, .rjs to .js.rjs, .rxml to .xml.builder, and .haml to .html.haml' | |
task 'rename' do | |
{'rhtml' => 'html.erb', 'rxml' => 'xml.builder', 'rjs' => 'js.rjs'}.each do |from_ext, to_ext| | |
Dir[File.join('app/views', "**", "*.#{from_ext}")].each do |from_path| | |
to_path = from_path.chomp(from_ext) + to_ext | |
puts `#{MOVE_COMMAND} #{from_path} #{to_path}` | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment