Rename Rails App - for Rails v6

Rename rails app using a patched rename gem supporting Rails 6
Icons/chart bar
Used 21 times
Created by
R Richard Logwood

Usage
Before Running 
Close any open editors or IDEs to prevent cached files from being written

After Running
cd .. 
cd YourNewNameHere
bin/bundle remove rename

Confirm the changes before committing
# re-bundle after removing rename
bin/bundle

# confirm changes
git diff 

* NOTE:  Forked from Rename Rails App in order to use rename gem patched for Rails 6
* NOTE: See rename gem patch details at pull request Add support for Rails 6.1.3.1

Run this command in your Rails app directory in the terminal:

rails app:template LOCATION="https://railsbytes.com/script/VWesZK"
Template Source

Review the code before running this template on your machine.

# coding: utf-8
#
# Please peform the manual steps indicated at the end
#
# Note: tests on Ubuntu 20.04.2 LTS, haven't found a way to successfully
#       cd back to new parent, hence the commands listed at end must be run
#       manally
#
# TODO: Test on MacBook
# TODO: Find out if there is a way to force thor run into a new directory context

require 'pathname'
pn  = Pathname.new(Dir.pwd)
old_dir = pn.basename
parent_dir = pn.dirname

chdir_error_regex = /No such file or directory @ dir_chdir - .*#{old_dir}/

name = ask("Enter new name for your Rails app:")

renamed_dir = "#{parent_dir}/#{name}"

puts "💎 Adding gem 'rename'"
# use patched rename gem that supports Rails 6
# see pull request https://github.com/morshedalam/rename/pull/12
run "bin/bundle add rename --git https://github.com/rlogwood/rename.git --branch rails_6.1.3.1"

begin
  rails_command "g rename:into #{name}"
rescue Exception => e
  if e.message =~ chdir_error_regex
    # ignore cd error that occurs on removed directory
    puts "ignoring error #{e.message}"
  else
    raise e
  end
end

puts "Completed rename"

puts "***\n*** Please run these commands manually:\n***\n"
puts "cd #{renamed_dir}"
puts "bin/bundle remove rename"
puts "bin/bundle"
puts "git status"
puts "git diff"

Comments

Sign up or Login to leave a comment.