I’m working on an app that can be downloaded and, once the user runs a rake file, will rename the original app to a name the user gives. What’s the best way to do that?
Here are the details. The app is located here: github.com/bnd5k/framework. It’s a basic webapp (has homepages, user authentication, testing setup). I’d like to set it up so that the user clones the repo of “Framework,” cd’s into that directory, and runs a rake task that does the renaming. But somehow I need the rake file to ask the user what they want as a new name for their app. That’s where I’m stuck
In the current version of this project, I’m doing this renaming through views. The user runs localhost and then in their browser, the default view is Namer/new. They rename the app there and the Namer controller renames all the necessay files. Problem is that it crashes at the point at which the app name change in the routes file. So, at this point, I’m figuring I should avoid the GUI issue entirely and just have the user do the name change at the terminal. If you disagree, let me know. Any suggestions would be helpful.
UPDATE: So I went with Marc’s comment below and am just requiring the user to enter the new name as part of the argument. My code works…sorta. When I type this: rake rename:changename[Funk], the code below changes the name. Unfortunately, it changes the name to “new_name”, instead of to “Funk.” Any ideas on what I’m going wrong?
namespace :rename do
desc 'changes the name of the app'
task :changename, :new_name do
file_names = ['config/environments/test.rb', 'config/environments/production.rb',
'config/environment.rb']
file_names.each do |file_name|
text = File.read(file_name)
File.open(file_name, "w") { |file| file << text.gsub("Framework", :new_name.to_s) }
end
end
end
Try this inside your rake task: