rename 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +8 -2
- data/lib/generators/rename/shared/common_methods.rb +66 -11
- data/lib/rename/version.rb +1 -1
- data/tests/hyphen_handling_test.rb +126 -0
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f9103bd6950e096f966b148dd5a186d10deee5de51b33f659c992e102d7be6f0
|
|
4
|
+
data.tar.gz: 8cb7182693d49c6197b03cdcacf8081ebf5dbb29c3ed387704c8a58545958603
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d5d6c617e7f321a063e18a3ed2f3e206956f47c606fcbb09d0b1f2fec60b091ebdac9bdcb78587beeaa02a7d3aba4fc1de9db71d59d4c6cbe778412f846cf815
|
|
7
|
+
data.tar.gz: ef0dcb01aa5d90c5e776e224e2eaec29601758effee2e156eb4c6debc5973584d2a3e2d035575cd4152b6284db4d128fa558f347e9f5b40686d40532513ee196
|
data/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
This gem allows you to rename your Rails application by using a single command.
|
|
4
4
|
|
|
5
|
-
Tested up to Ruby 3.
|
|
5
|
+
Tested up to Ruby 3.4.5 and Rails 8.0.2
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -41,18 +41,24 @@ Search and replace exact module name to...
|
|
|
41
41
|
config/initializers/permissions_policy.rb
|
|
42
42
|
config/puma.rb
|
|
43
43
|
config/routes.rb
|
|
44
|
+
config/deploy.yml (Rails 8)
|
|
44
45
|
app/views/layouts/application.html.erb
|
|
45
46
|
app/views/layouts/application.html.haml
|
|
46
47
|
app/views/layouts/application.html.slim
|
|
48
|
+
app/views/pwa/manifest.json.erb (Rails 8)
|
|
47
49
|
README.md
|
|
48
50
|
README.markdown
|
|
49
51
|
README.mdown
|
|
50
52
|
README.mkdn
|
|
53
|
+
Dockerfile (if present)
|
|
51
54
|
Search and replace underscore seperated module name to...
|
|
52
|
-
config/initializers/session_store.rb
|
|
55
|
+
config/initializers/session_store.rb (if present)
|
|
53
56
|
config/database.yml
|
|
57
|
+
config/database.yml (Rails 8 multi-db: cache, queue, cable)
|
|
58
|
+
config/database.yml (environment variables)
|
|
54
59
|
config/cable.yml
|
|
55
60
|
config/environments/production.rb
|
|
61
|
+
config/deploy.yml (Rails 8 Kamal service names)
|
|
56
62
|
package.json
|
|
57
63
|
Removing references...
|
|
58
64
|
.idea
|
|
@@ -28,10 +28,17 @@ module CommonMethods
|
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def prepare_app_vars
|
|
31
|
-
@new_key = new_name.gsub(/\W/, '_')
|
|
32
31
|
@old_module_name = app_parent
|
|
33
32
|
@old_dir = File.basename(Dir.getwd)
|
|
34
|
-
@
|
|
33
|
+
@old_app_name = detect_app_name || @old_module_name.underscore
|
|
34
|
+
|
|
35
|
+
# Normalize old directory name using ActiveSupport to handle hyphens
|
|
36
|
+
# If the directory has hyphens, the database name would have underscores
|
|
37
|
+
@old_app_name_from_dir = @old_dir.parameterize(separator: '_')
|
|
38
|
+
|
|
39
|
+
@new_app_name = new_name.parameterize(separator: '_').gsub('-', '_')
|
|
40
|
+
@new_module_name = @new_app_name.camelize
|
|
41
|
+
@new_key = @new_app_name
|
|
35
42
|
@new_dir = new_name.gsub(/[&%*@()!{}\[\]'\\\/"]+/, '')
|
|
36
43
|
@new_path = Rails.root.to_s.split('/')[0...-1].push(@new_dir).join('/')
|
|
37
44
|
end
|
|
@@ -47,7 +54,7 @@ module CommonMethods
|
|
|
47
54
|
raise Thor::Error, '[Error] Please give a name which does not match any of the reserved Rails keywords.'
|
|
48
55
|
elsif Object.const_defined?(@new_module_name)
|
|
49
56
|
raise Thor::Error, "[Error] Constant '#{@new_module_name}' is already in use, please choose another name."
|
|
50
|
-
elsif file_exist?(@new_path)
|
|
57
|
+
elsif file_exist?(@new_path) && @new_path != Rails.root.to_s
|
|
51
58
|
raise Thor::Error, "[Error] Folder '#{@new_dir}' already in use, please choose another name."
|
|
52
59
|
end
|
|
53
60
|
end
|
|
@@ -56,32 +63,59 @@ module CommonMethods
|
|
|
56
63
|
def apply_new_module_name
|
|
57
64
|
in_root do
|
|
58
65
|
puts 'Search and replace exact module name...'
|
|
59
|
-
Dir['*', 'config/**/**/*.rb', '.{rvmrc}'].each do |file|
|
|
60
|
-
|
|
61
|
-
replace_into_file(file, /(#{@old_module_name}*)/m, @new_module_name)
|
|
66
|
+
Dir['*', 'config/**/**/*.{rb,yml}', '.{rvmrc}', 'app/views/pwa/*.json.erb'].each do |file|
|
|
67
|
+
replace_into_file(file, /#{@old_module_name}/, @new_module_name)
|
|
62
68
|
end
|
|
63
69
|
#Application layout
|
|
64
70
|
%w(erb haml slim).each do |ext|
|
|
65
71
|
replace_into_file("app/views/layouts/application.html.#{ext}", /#{@old_module_name}/, @new_module_name)
|
|
72
|
+
replace_into_file("app/views/layouts/application.html.#{ext}", /#{@old_module_name.underscore.humanize}/, @new_module_name.underscore.humanize)
|
|
66
73
|
end
|
|
67
74
|
#Readme
|
|
68
75
|
%w(md markdown mdown mkdn).each do |ext|
|
|
69
76
|
replace_into_file("README.#{ext}", /#{@old_module_name}/, @new_module_name)
|
|
70
77
|
end
|
|
71
78
|
|
|
72
|
-
puts 'Search and replace underscore
|
|
79
|
+
puts 'Search and replace underscore separated module name in files...'
|
|
73
80
|
#session key
|
|
74
|
-
|
|
81
|
+
safe_replace_into_file('config/initializers/session_store.rb', /(('|")_.*_session('|"))/i, "'_#{@new_key}_session'")
|
|
75
82
|
#database
|
|
76
|
-
|
|
83
|
+
# Try both the detected app name and the directory-based name (with underscores)
|
|
84
|
+
replace_into_file('config/database.yml', /#{@old_app_name}/i, @new_app_name)
|
|
85
|
+
replace_into_file('config/database.yml', /#{@old_app_name_from_dir}/i, @new_app_name) if @old_app_name != @old_app_name_from_dir
|
|
86
|
+
replace_into_file('config/database.yml', /#{@old_app_name}_(production|development|test)(_cache|_queue|_cable)?/, "#{@new_app_name}_\\1\\2")
|
|
87
|
+
replace_into_file('config/database.yml', /#{@old_app_name_from_dir}_(production|development|test)(_cache|_queue|_cable)?/, "#{@new_app_name}_\\1\\2") if @old_app_name != @old_app_name_from_dir
|
|
88
|
+
replace_into_file('config/database.yml', /#{@old_app_name.upcase}_DATABASE_PASSWORD/, "#{@new_app_name.upcase}_DATABASE_PASSWORD")
|
|
89
|
+
replace_into_file('config/database.yml', /#{@old_app_name_from_dir.upcase}_DATABASE_PASSWORD/, "#{@new_app_name.upcase}_DATABASE_PASSWORD") if @old_app_name != @old_app_name_from_dir
|
|
77
90
|
#Channel and job queue
|
|
78
91
|
%w(config/cable.yml config/environments/production.rb).each do |file|
|
|
79
|
-
replace_into_file(file, /#{@
|
|
92
|
+
replace_into_file(file, /#{@old_app_name}_production/, "#{@new_app_name}_production")
|
|
93
|
+
replace_into_file(file, /#{@old_app_name_from_dir}_production/, "#{@new_app_name}_production") if @old_app_name != @old_app_name_from_dir
|
|
80
94
|
end
|
|
81
95
|
# package.json name entry
|
|
82
96
|
old_package_name_regex = /\Wname\W *: *\W(?<name>[-_\p{Alnum}]+)\W *, */i
|
|
83
|
-
new_package_name = %("name":"#{@
|
|
97
|
+
new_package_name = %("name":"#{@new_app_name}",)
|
|
84
98
|
replace_into_file('package.json', old_package_name_regex, new_package_name)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
# Rails 8 specific files
|
|
102
|
+
# Kamal deployment configuration
|
|
103
|
+
safe_replace_into_file('config/deploy.yml', /service: #{@old_app_name}/, "service: #{@new_app_name}")
|
|
104
|
+
safe_replace_into_file('config/deploy.yml', /service: #{@old_app_name_from_dir}/, "service: #{@new_app_name}") if @old_app_name != @old_app_name_from_dir
|
|
105
|
+
safe_replace_into_file('config/deploy.yml', /image: (.+)\/#{@old_app_name}/, "image: \\1/#{@new_app_name}")
|
|
106
|
+
safe_replace_into_file('config/deploy.yml', /image: (.+)\/#{@old_app_name_from_dir}/, "image: \\1/#{@new_app_name}") if @old_app_name != @old_app_name_from_dir
|
|
107
|
+
safe_replace_into_file('config/deploy.yml', /"#{@old_app_name}_/, "\"#{@new_app_name}_")
|
|
108
|
+
safe_replace_into_file('config/deploy.yml', /"#{@old_app_name_from_dir}_/, "\"#{@new_app_name}_") if @old_app_name != @old_app_name_from_dir
|
|
109
|
+
safe_replace_into_file('config/deploy.yml', /#{@old_app_name}-db/, "#{@new_app_name}-db")
|
|
110
|
+
safe_replace_into_file('config/deploy.yml', /#{@old_app_name_from_dir}-db/, "#{@new_app_name}-db") if @old_app_name != @old_app_name_from_dir
|
|
111
|
+
|
|
112
|
+
# PWA manifest
|
|
113
|
+
safe_replace_into_file('app/views/pwa/manifest.json.erb', /"name": "#{@old_module_name}"/, "\"name\": \"#{@new_module_name}\"")
|
|
114
|
+
safe_replace_into_file('app/views/pwa/manifest.json.erb', /"description": "#{@old_module_name}/, "\"description\": \"#{@new_module_name}")
|
|
115
|
+
|
|
116
|
+
# Dockerfile
|
|
117
|
+
safe_replace_into_file('Dockerfile', /#{@old_module_name}/, @new_module_name)
|
|
118
|
+
safe_replace_into_file('Dockerfile', /#{@old_app_name}/, @new_app_name)
|
|
85
119
|
end
|
|
86
120
|
end
|
|
87
121
|
|
|
@@ -91,6 +125,22 @@ module CommonMethods
|
|
|
91
125
|
@reserved_names = %w[application destroy benchmarker profiler plugin runner test]
|
|
92
126
|
end
|
|
93
127
|
|
|
128
|
+
def detect_app_name
|
|
129
|
+
return nil unless file_exist?('config/database.yml')
|
|
130
|
+
|
|
131
|
+
database_content = File.read('config/database.yml')
|
|
132
|
+
|
|
133
|
+
if match = database_content.match(/^\s*database:\s*(\w+)_development/m)
|
|
134
|
+
app_name_candidate = match[1]
|
|
135
|
+
|
|
136
|
+
if app_name_candidate.camelize == @old_module_name
|
|
137
|
+
return app_name_candidate
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
nil
|
|
142
|
+
end
|
|
143
|
+
|
|
94
144
|
def file_exist?(name)
|
|
95
145
|
File.respond_to?(:exist?) ? File.exist?(name) : File.exists?(name)
|
|
96
146
|
end
|
|
@@ -129,4 +179,9 @@ module CommonMethods
|
|
|
129
179
|
puts "Error: #{ex.message}"
|
|
130
180
|
end
|
|
131
181
|
end
|
|
182
|
+
|
|
183
|
+
def safe_replace_into_file(file, search_exp, replace)
|
|
184
|
+
return unless file_exist?(file) && !File.directory?(file)
|
|
185
|
+
replace_into_file(file, search_exp, replace)
|
|
186
|
+
end
|
|
132
187
|
end
|
data/lib/rename/version.rb
CHANGED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'fileutils'
|
|
3
|
+
require 'tmpdir'
|
|
4
|
+
|
|
5
|
+
class HyphenHandlingTest < ActiveSupport::TestCase
|
|
6
|
+
def setup
|
|
7
|
+
@temp_dir = Dir.mktmpdir
|
|
8
|
+
@original_dir = Dir.pwd
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def teardown
|
|
12
|
+
Dir.chdir(@original_dir)
|
|
13
|
+
FileUtils.rm_rf(@temp_dir)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
test "handles app names with hyphens correctly" do
|
|
17
|
+
# Create a mock Rails app structure with hyphenated name
|
|
18
|
+
app_dir = File.join(@temp_dir, 'api-proxy')
|
|
19
|
+
FileUtils.mkdir_p(File.join(app_dir, 'config'))
|
|
20
|
+
|
|
21
|
+
# Create database.yml with underscore naming (as Rails would)
|
|
22
|
+
database_yml = <<~YAML
|
|
23
|
+
default: &default
|
|
24
|
+
adapter: postgresql
|
|
25
|
+
encoding: unicode
|
|
26
|
+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
|
27
|
+
|
|
28
|
+
development:
|
|
29
|
+
<<: *default
|
|
30
|
+
database: api_proxy_development
|
|
31
|
+
|
|
32
|
+
test:
|
|
33
|
+
<<: *default
|
|
34
|
+
database: api_proxy_test
|
|
35
|
+
|
|
36
|
+
production:
|
|
37
|
+
<<: *default
|
|
38
|
+
database: api_proxy_production
|
|
39
|
+
username: api_proxy
|
|
40
|
+
password: <%= ENV["API_PROXY_DATABASE_PASSWORD"] %>
|
|
41
|
+
YAML
|
|
42
|
+
|
|
43
|
+
File.write(File.join(app_dir, 'config', 'database.yml'), database_yml)
|
|
44
|
+
|
|
45
|
+
# Create cable.yml
|
|
46
|
+
cable_yml = <<~YAML
|
|
47
|
+
production:
|
|
48
|
+
adapter: redis
|
|
49
|
+
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
|
|
50
|
+
channel_prefix: api_proxy_production
|
|
51
|
+
YAML
|
|
52
|
+
|
|
53
|
+
File.write(File.join(app_dir, 'config', 'cable.yml'), cable_yml)
|
|
54
|
+
|
|
55
|
+
Dir.chdir(app_dir) do
|
|
56
|
+
# Simulate the prepare_app_vars method
|
|
57
|
+
old_dir = File.basename(Dir.getwd)
|
|
58
|
+
assert_equal 'api-proxy', old_dir
|
|
59
|
+
|
|
60
|
+
# Test the normalization
|
|
61
|
+
old_app_name_from_dir = old_dir.parameterize(separator: '_')
|
|
62
|
+
assert_equal 'api_proxy', old_app_name_from_dir
|
|
63
|
+
|
|
64
|
+
# Verify the fix would work
|
|
65
|
+
new_app_name = 'citadel'.parameterize(separator: '_')
|
|
66
|
+
assert_equal 'citadel', new_app_name
|
|
67
|
+
|
|
68
|
+
# Read the database.yml and verify it contains the underscore version
|
|
69
|
+
db_content = File.read(File.join('config', 'database.yml'))
|
|
70
|
+
assert db_content.include?('api_proxy_development')
|
|
71
|
+
assert db_content.include?('api_proxy_test')
|
|
72
|
+
assert db_content.include?('api_proxy_production')
|
|
73
|
+
assert db_content.include?('API_PROXY_DATABASE_PASSWORD')
|
|
74
|
+
|
|
75
|
+
# Read cable.yml
|
|
76
|
+
cable_content = File.read(File.join('config', 'cable.yml'))
|
|
77
|
+
assert cable_content.include?('api_proxy_production')
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
test "handles normal app names without hyphens" do
|
|
82
|
+
app_dir = File.join(@temp_dir, 'myapp')
|
|
83
|
+
FileUtils.mkdir_p(File.join(app_dir, 'config'))
|
|
84
|
+
|
|
85
|
+
database_yml = <<~YAML
|
|
86
|
+
development:
|
|
87
|
+
database: myapp_development
|
|
88
|
+
YAML
|
|
89
|
+
|
|
90
|
+
File.write(File.join(app_dir, 'config', 'database.yml'), database_yml)
|
|
91
|
+
|
|
92
|
+
Dir.chdir(app_dir) do
|
|
93
|
+
old_dir = File.basename(Dir.getwd)
|
|
94
|
+
assert_equal 'myapp', old_dir
|
|
95
|
+
|
|
96
|
+
old_app_name_from_dir = old_dir.parameterize(separator: '_')
|
|
97
|
+
assert_equal 'myapp', old_app_name_from_dir
|
|
98
|
+
|
|
99
|
+
# In this case, old_app_name and old_app_name_from_dir should be the same
|
|
100
|
+
# So the conditional replacements won't run
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
test "handles complex app names with multiple hyphens" do
|
|
105
|
+
app_dir = File.join(@temp_dir, 'my-awesome-api-proxy')
|
|
106
|
+
FileUtils.mkdir_p(File.join(app_dir, 'config'))
|
|
107
|
+
|
|
108
|
+
database_yml = <<~YAML
|
|
109
|
+
development:
|
|
110
|
+
database: my_awesome_api_proxy_development
|
|
111
|
+
YAML
|
|
112
|
+
|
|
113
|
+
File.write(File.join(app_dir, 'config', 'database.yml'), database_yml)
|
|
114
|
+
|
|
115
|
+
Dir.chdir(app_dir) do
|
|
116
|
+
old_dir = File.basename(Dir.getwd)
|
|
117
|
+
assert_equal 'my-awesome-api-proxy', old_dir
|
|
118
|
+
|
|
119
|
+
old_app_name_from_dir = old_dir.parameterize(separator: '_')
|
|
120
|
+
assert_equal 'my_awesome_api_proxy', old_app_name_from_dir
|
|
121
|
+
|
|
122
|
+
db_content = File.read(File.join('config', 'database.yml'))
|
|
123
|
+
assert db_content.include?('my_awesome_api_proxy_development')
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rename
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1.
|
|
4
|
+
version: 1.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Morshed Alam
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-07-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -73,6 +73,7 @@ files:
|
|
|
73
73
|
- lib/rename.rb
|
|
74
74
|
- lib/rename/version.rb
|
|
75
75
|
- rename.gemspec
|
|
76
|
+
- tests/hyphen_handling_test.rb
|
|
76
77
|
- tests/rename_test.rb
|
|
77
78
|
- tests/test_helper.rb
|
|
78
79
|
homepage: https://github.com/morshedalam/rename
|
|
@@ -94,8 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
94
95
|
- !ruby/object:Gem::Version
|
|
95
96
|
version: '0'
|
|
96
97
|
requirements: []
|
|
97
|
-
|
|
98
|
-
rubygems_version: 2.7.11
|
|
98
|
+
rubygems_version: 3.5.11
|
|
99
99
|
signing_key:
|
|
100
100
|
specification_version: 4
|
|
101
101
|
summary: Rename your Rails application using a single command.
|