Last active
April 23, 2019 06:31
-
-
Save invisiblefunnel/8621409 to your computer and use it in GitHub Desktop.
Rake task for renaming a Rails app
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
desc "Rename this application" | |
task :rename, [:name] => :environment do |t, args| | |
files = Dir.glob(%w(rb yml).map{ |ext| Rails.root.join("**/*.#{ext}") } + %w(Rakefile)) | |
before = Rails.application.class.name.split('::').first | |
after = args.name or raise "Pass a new name as an argument: $ rake rename[MyCivicApp]" | |
files.each do |file| | |
# Swap in the new name | |
renamed = File.read(file).gsub(/#{before}/, after).gsub(/#{before.underscore}/, after.underscore) | |
# Write the updated contents | |
File.write(file, renamed) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
pllz send me company names updated code