Created
October 21, 2010 14:45
-
-
Save ebot/638598 to your computer and use it in GitHub Desktop.
A Rails 3 rake task for renaming the application
This file contains hidden or 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
namespace 'rails' do | |
desc 'Renames the current app' | |
task 'rename' do | |
# Get the new name | |
new_name = ENV["NEW_NAME"].capitalize || nil | |
if new_name.nil? | |
puts "\nYou must pass in a new name" | |
exit | |
end | |
# Get the current name of the app | |
current_name = IO.readlines('config/routes.rb').first.split('::')[0] | |
puts "Renaming #{current_name} to #{new_name}" | |
files = [ 'config.ru', | |
'rakefile', | |
'config/application.rb', | |
'config/environment.rb', | |
'config/routes.rb', | |
'config/environments/development.rb', | |
'config/environments/test.rb', | |
'config/environments/production.rb', | |
'config/initializers/secret_token.rb', | |
'config/initializers/session_store.rb' ] | |
files.each do |file| | |
puts " Updating #{file}" | |
input = IO.read(file) | |
output = File.new file, 'w' | |
output << input.gsub(current_name, new_name) | |
output.close | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment