Skip to content

Instantly share code, notes, and snippets.

@vertis
Created January 24, 2012 21:27
Show Gist options
  • Save vertis/1672812 to your computer and use it in GitHub Desktop.
Save vertis/1672812 to your computer and use it in GitHub Desktop.
Simple script that can be used to rename a rails3 app
#!/usr/bin/env ruby
require 'fileutils'
require 'tempfile'
def replace_in_file(filename,oldvalue,newvalue)
temp_file = Tempfile.new(File.basename(filename))
contents = File.read(filename)
changed_contents = contents.gsub(oldvalue,newvalue).gsub(oldvalue.downcase,newvalue.downcase)
temp_file.print(changed_contents)
temp_file.close
FileUtils.mv(temp_file.path, filename)
end
if ARGV.count!=2
puts "Usage: rename_rails3 <Oldname> <Newname>"
exit 1
end
oldname = ARGV[0]
newname = ARGV[1]
other_files = [".rvmrc", "config.ru", "Rakefile"].select {|other| File.exists?(other) }
targets = Dir['**/*.{erb,haml,rb,sh,yml}'] + other_files
targets.each do |target|
puts target
replace_in_file(target,oldname,newname)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment