rename-rails 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rubocop.yml +21 -0
- data/.ruby-version +1 -0
- data/Gemfile +6 -0
- data/LICENSE +20 -0
- data/README.md +36 -0
- data/Rakefile +4 -0
- data/lib/generators/rename_rails/app_to/USAGE +1 -0
- data/lib/generators/rename_rails/app_to/app_to_generator.rb +16 -0
- data/lib/generators/rename_rails/into/USAGE +1 -0
- data/lib/generators/rename_rails/into/into_generator.rb +15 -0
- data/lib/generators/rename_rails/shared/common_methods.rb +142 -0
- data/lib/rename_rails.rb +5 -0
- data/lib/rename_rails/version.rb +5 -0
- data/rename_rails.gemspec +21 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 631d72108be39543d3d3f40400e9d306d92c04f96d77a80a8664a9ad87f528a7
|
4
|
+
data.tar.gz: fc3dd19e44e55e47d37e3a3f9f291167af6f02da2d0b05a48c8294e748164d9d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b8e7406078cd5073f70111cbc4e30b2217021d9da5ff54a380551924fd9b579ba917687722207e92ac00d1ed92cee070db0771b25719385148d28d280e875038
|
7
|
+
data.tar.gz: 0ceb8bec89186fc0a2dfcd0377a771187866de558834745ee2c7e3174f5457f06e66d6ffcd478697e79c4a4254bd1b8af8ad8b0302a3d090a8c267ef2cc3adab
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 3.0
|
3
|
+
NewCops: enable
|
4
|
+
|
5
|
+
Metrics/AbcSize:
|
6
|
+
Enabled: false
|
7
|
+
|
8
|
+
Metrics/MethodLength:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
Style/Documentation:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Style/StringLiterals:
|
15
|
+
EnforcedStyle: double_quotes
|
16
|
+
|
17
|
+
Style/IfUnlessModifier:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Style/GuardClause:
|
21
|
+
Enabled: false
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.0.1
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
rename-rails
|
2
|
+
============
|
3
|
+
|
4
|
+
This gem allows you to rename your Rails application by using a single command.
|
5
|
+
|
6
|
+
Fork of [rename][rename] by [@morshedalam][], with updates for Rails 6 provided by [@rlogwood][].
|
7
|
+
|
8
|
+
[rename]: https://github.com/morshedalam/rename
|
9
|
+
[@morshedalam]: https://github.com/morshedalam
|
10
|
+
[@rlogwood]: https://github.com/rlogwood
|
11
|
+
|
12
|
+
|
13
|
+
Installation
|
14
|
+
------------
|
15
|
+
|
16
|
+
Add the following to your Rails app's `Gemfile` and `bundle install`:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem "rename"
|
20
|
+
```
|
21
|
+
|
22
|
+
Usage
|
23
|
+
-----
|
24
|
+
|
25
|
+
```sh
|
26
|
+
$ rails generate rename:into NewAppName
|
27
|
+
```
|
28
|
+
|
29
|
+
Contributing
|
30
|
+
------------
|
31
|
+
|
32
|
+
1. Fork it
|
33
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
34
|
+
3. Commit your changes (`git commit -am "Added some feature'`)
|
35
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
36
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rails generate rename:app_to NewAppName
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path("../shared/common_methods", File.dirname(__FILE__))
|
4
|
+
|
5
|
+
module RenameRails
|
6
|
+
module Generators
|
7
|
+
class AppToGenerator < Rails::Generators::Base
|
8
|
+
include CommonMethods
|
9
|
+
|
10
|
+
def app_to
|
11
|
+
warn "[DEPRECATION] `app_to` is deprecated. Please use `into` instead."
|
12
|
+
perform
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
rails g rename:into NewName
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path("../shared/common_methods", File.dirname(__FILE__))
|
4
|
+
|
5
|
+
module RenameRails
|
6
|
+
module Generators
|
7
|
+
class IntoGenerator < Rails::Generators::Base
|
8
|
+
include CommonMethods
|
9
|
+
|
10
|
+
def into
|
11
|
+
perform
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
|
5
|
+
module CommonMethods
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
desc "Rename your Rails application"
|
10
|
+
|
11
|
+
argument :new_name, type: :string, default: ""
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
def perform
|
17
|
+
prepare_app_vars
|
18
|
+
validate_name_and_path?
|
19
|
+
apply_new_module_name
|
20
|
+
change_app_directory
|
21
|
+
end
|
22
|
+
|
23
|
+
def app_parent
|
24
|
+
if Rails::VERSION::MAJOR >= 6
|
25
|
+
Rails.application.class.module_parent.name
|
26
|
+
else
|
27
|
+
Rails.application.class.parent.name
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def prepare_app_vars
|
32
|
+
@new_key = new_name.gsub(/\W/, "_")
|
33
|
+
@old_module_name = app_parent
|
34
|
+
@new_module_name = @new_key.squeeze("_").camelize
|
35
|
+
@new_dir = new_name.gsub(%r{[&%*@()!{}\[\]'\\/"]+}, "")
|
36
|
+
@new_path = Rails.root.to_s.split("/")[0...-1].push(@new_dir).join("/")
|
37
|
+
end
|
38
|
+
|
39
|
+
def validate_name_and_path?
|
40
|
+
if new_name.blank?
|
41
|
+
raise Thor::Error, "[Error] Application name can't be blank."
|
42
|
+
elsif /^\d/.match?(new_name)
|
43
|
+
raise Thor::Error, "[Error] Please give a name which does not start with numbers."
|
44
|
+
elsif @new_module_name.empty?
|
45
|
+
raise Thor::Error, "[Error] Please enter at least one alphabet."
|
46
|
+
elsif reserved_names.include?(@new_module_name.downcase)
|
47
|
+
raise Thor::Error, "[Error] Please give a name which does not match any of the reserved Rails keywords."
|
48
|
+
elsif Object.const_defined?(@new_module_name)
|
49
|
+
raise Thor::Error, "[Error] Constant #{@new_module_name} is already in use, please choose another name."
|
50
|
+
elsif File.exist?(@new_path)
|
51
|
+
raise Thor::Error, "[Error] Already in use, please choose another name."
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# rename_app_to_new_app_module
|
56
|
+
def apply_new_module_name
|
57
|
+
in_root do
|
58
|
+
puts "Search and replace module in..."
|
59
|
+
|
60
|
+
# Search and replace module in to file
|
61
|
+
Dir["*", "config/**/**/*.rb", ".{rvmrc}"].each do |file|
|
62
|
+
# file = File.join(Dir.pwd, file)
|
63
|
+
replace_into_file(file, /(#{@old_module_name}*)/m, @new_module_name)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Rename session key
|
67
|
+
replace_into_file("config/initializers/session_store.rb", /(('|")_.*_session('|"))/i, "'_#{@new_key}_session'")
|
68
|
+
# Rename database
|
69
|
+
replace_into_file("config/database.yml", /#{@old_module_name.underscore}/i, @new_name.underscore)
|
70
|
+
|
71
|
+
# Update package.json name entry
|
72
|
+
old_package_name_regex = /\Wname\W *: *\W(?<name>[-_\p{Alnum}]+)\W *, */i
|
73
|
+
new_package_name = %("name":"#{@new_module_name.underscore}",)
|
74
|
+
replace_into_file("package.json", old_package_name_regex, new_package_name)
|
75
|
+
|
76
|
+
# Update app/views/layouts/application.html.erb title
|
77
|
+
replace_into_file("app/views/layouts/application.html.erb", "<title>#{@old_module_name}</title>",
|
78
|
+
"<title>#{@new_module_name}</title>")
|
79
|
+
|
80
|
+
# Update channel prefix config/cable.yml
|
81
|
+
replace_into_file("config/cable.yml", "#{@old_module_name.underscore}_production",
|
82
|
+
"#{@new_module_name.underscore}_production")
|
83
|
+
|
84
|
+
# Update config/environments/production.rb # config.active_job.queue_name_prefix = "(myapp)_production"
|
85
|
+
replace_into_file("config/environments/production.rb", "#{@old_module_name.underscore}_production",
|
86
|
+
"#{@new_module_name.underscore}_production")
|
87
|
+
|
88
|
+
# config/database.yml capitalize environment variable
|
89
|
+
replace_into_file("config/database.yml", "ENV['#{@new_module_name.underscore}_DATABASE_PASSWORD']",
|
90
|
+
"ENV['#{@new_module_name.underscore.upcase}_DATABASE_PASSWORD']")
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# rename_app_to_new_app_directory
|
95
|
+
def change_app_directory
|
96
|
+
rename_references
|
97
|
+
rename_directory
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
def reserved_names
|
103
|
+
@reserved_names = %w[application destroy benchmarker profiler plugin runner test]
|
104
|
+
end
|
105
|
+
|
106
|
+
def rename_references
|
107
|
+
puts "Renaming references..."
|
108
|
+
old_basename = File.basename(Dir.getwd)
|
109
|
+
|
110
|
+
in_root do
|
111
|
+
Dir.glob(".idea/*", File::FNM_DOTMATCH).each do |file|
|
112
|
+
replace_into_file(file, old_basename, @new_dir)
|
113
|
+
end
|
114
|
+
|
115
|
+
gem_set_file = ".ruby-gemset"
|
116
|
+
replace_into_file(gem_set_file, old_basename, @new_dir) if File.exist?(gem_set_file)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def rename_directory
|
121
|
+
print "Renaming directory..."
|
122
|
+
|
123
|
+
begin
|
124
|
+
# FileUtils.mv Dir.pwd, app_path
|
125
|
+
File.rename(Rails.root.to_s, @new_path)
|
126
|
+
puts "Done!"
|
127
|
+
puts "New application path is '#{@new_path}'"
|
128
|
+
rescue StandardError => e
|
129
|
+
puts "Error:#{e.inspect}"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def replace_into_file(file, search_exp, replace)
|
134
|
+
return if File.directory?(file)
|
135
|
+
|
136
|
+
begin
|
137
|
+
gsub_file file, search_exp, replace
|
138
|
+
rescue StandardError => e
|
139
|
+
puts "Error: #{e.message}"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
data/lib/rename_rails.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path("lib/rename_rails/version", __dir__)
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "rename-rails"
|
7
|
+
gem.version = RenameRails::VERSION
|
8
|
+
gem.licenses = ["MIT"]
|
9
|
+
gem.summary = "Rename your Rails application using a single command."
|
10
|
+
gem.authors = ["Morshed Alam", "Richard Logwood", "Jake Romer"]
|
11
|
+
gem.email = "jake@jmromer.org"
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.homepage = "https://github.com/jmromer/rename-rails"
|
14
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
15
|
+
gem.require_paths = %w[lib]
|
16
|
+
|
17
|
+
gem.required_ruby_version = "~> 3.0"
|
18
|
+
gem.add_dependency "rails", "~> 6.1"
|
19
|
+
gem.add_dependency "thor", "~> 1.1"
|
20
|
+
gem.add_runtime_dependency "activesupport", "~> 6.1"
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rename-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Morshed Alam
|
8
|
+
- Richard Logwood
|
9
|
+
- Jake Romer
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2021-06-09 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rails
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - "~>"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '6.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "~>"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '6.1'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: thor
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - "~>"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '1.1'
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '1.1'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: activesupport
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '6.1'
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '6.1'
|
57
|
+
description:
|
58
|
+
email: jake@jmromer.org
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rubocop.yml"
|
65
|
+
- ".ruby-version"
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- lib/generators/rename_rails/app_to/USAGE
|
71
|
+
- lib/generators/rename_rails/app_to/app_to_generator.rb
|
72
|
+
- lib/generators/rename_rails/into/USAGE
|
73
|
+
- lib/generators/rename_rails/into/into_generator.rb
|
74
|
+
- lib/generators/rename_rails/shared/common_methods.rb
|
75
|
+
- lib/rename_rails.rb
|
76
|
+
- lib/rename_rails/version.rb
|
77
|
+
- rename_rails.gemspec
|
78
|
+
homepage: https://github.com/jmromer/rename-rails
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '3.0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubygems_version: 3.2.15
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Rename your Rails application using a single command.
|
101
|
+
test_files: []
|