I’ve got a rake task that renames a bunch of stuff in various files. So, if someone at the cmd terminal writes this
rename:namechange[funk]
the code below should perform the necessary find/replace. My problem is that I can’t get this line to work.
args[:new_name.capitalize]
Any idea why?
namespace :rename do
desc 'changes the name of the app'
task :changename, :new_name do |task, args|
args[:new_name.capitalize]
# change any instances of the term "framework" to the new name of the app
#for testing, just change these: file_names = ['config/environment.rb'] #['config/environments/test.rb', 'config/environments/production.rb', 'config/environment.rb']
file_names = ['app/helpers/application_helper.rb', 'app/views/pages/home.html.erb', 'rakefile', 'config/application.rb', 'config.ru', 'config/database.yml',
'config/environments/development.rb', 'config/environments/test.rb', 'config/environments/production.rb',
'config/environment.rb', 'config/initializers/secret_token.rb', 'config/initializers/session_store.rb', 'config/routes.rb',
'spec/controllers/pages_controller_spec.rb']
file_names.each do |file_name|
text = File.read(file_name)
File.open(file_name, "w") { |file| file << text.gsub("Framework", args[:new_name]) }
end
end
end
UPDATE: I had trouble with “.capitalize” because it automatically put any character after the first as a lowercase letter. Ultimately, I arrived at this:
args[:new_name][0] = args[:new_name].capitalize[0]
Did you mean to write one of these: