rename 1.0.8 → 1.0.9
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/lib/generators/rename/shared/common_methods.rb +139 -135
- data/lib/rename/version.rb +3 -3
- data/rename.gemspec +21 -21
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59dcefa0ad39fd863840b89bfaa4b6d79395009d63c489243fbea126496a901a
|
4
|
+
data.tar.gz: 3125cd4d95bb1d153ae31f2c6e21e8a6cce0232ccbe7d3115307de3215a5bb2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc304eb7f357c6b8adc6ed8daefd10460c417df186050574035b4c63ea7ede4a555fff2e1355cf4e6e03d7e4459c88a6ba7b980acebe4b4b18c5b1cdd8848bb1
|
7
|
+
data.tar.gz: 7af04e3ac1bfb29ca8596d40dfad2434ccc4578d16a53d8bc3d1edaedb4f9b464171fdde8fa924891d99afa7da6612ebbca1c9486948f7cd342b68867c232918
|
@@ -1,135 +1,139 @@
|
|
1
|
-
require 'active_support/concern'
|
2
|
-
|
3
|
-
module CommonMethods
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
included do
|
7
|
-
desc 'Rename your Rails application'
|
8
|
-
|
9
|
-
argument :new_name, :type => :string, :default => ''
|
10
|
-
end
|
11
|
-
|
12
|
-
protected
|
13
|
-
|
14
|
-
def perform
|
15
|
-
prepare_app_vars
|
16
|
-
validate_name_and_path?
|
17
|
-
apply_new_module_name
|
18
|
-
change_app_directory
|
19
|
-
end
|
20
|
-
|
21
|
-
def app_parent
|
22
|
-
if Rails.version.to_f >= 3.3
|
23
|
-
Rails.application.class.to_s.deconstantize
|
24
|
-
else
|
25
|
-
Rails.application.class.parent.name
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def prepare_app_vars
|
30
|
-
@new_key = new_name.gsub(/\W/, '_')
|
31
|
-
@old_module_name = app_parent
|
32
|
-
@new_module_name = @new_key.squeeze('_').camelize
|
33
|
-
@new_dir = new_name.gsub(/[&%*@()!{}\[\]'\\\/"]+/, '')
|
34
|
-
@new_path = Rails.root.to_s.split('/')[0...-1].push(@new_dir).join('/')
|
35
|
-
end
|
36
|
-
|
37
|
-
def validate_name_and_path?
|
38
|
-
if new_name.blank?
|
39
|
-
raise Thor::Error, "[Error] Application name can't be blank."
|
40
|
-
elsif new_name =~ /^\d/
|
41
|
-
raise Thor::Error, '[Error] Please give a name which does not start with numbers.'
|
42
|
-
elsif @new_module_name.size < 1
|
43
|
-
raise Thor::Error, '[Error] Please enter at least one alphabet.'
|
44
|
-
elsif reserved_names.include?(@new_module_name.downcase)
|
45
|
-
raise Thor::Error, '[Error] Please give a name which does not match any of the reserved Rails keywords.'
|
46
|
-
elsif Object.const_defined?(@new_module_name)
|
47
|
-
raise Thor::Error, "[Error] Constant #{@new_module_name} is already in use, please choose another name."
|
48
|
-
elsif
|
49
|
-
raise Thor::Error, '[Error] Already in use, please choose another name.'
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# rename_app_to_new_app_module
|
54
|
-
def apply_new_module_name
|
55
|
-
in_root do
|
56
|
-
puts 'Search and replace module in files...'
|
57
|
-
|
58
|
-
#Search and replace module in to file
|
59
|
-
Dir['*', 'config/**/**/*.rb', '.{rvmrc}'].each do |file|
|
60
|
-
# file = File.join(Dir.pwd, file)
|
61
|
-
replace_into_file(file, /(#{@old_module_name}*)/m, @new_module_name)
|
62
|
-
end
|
63
|
-
|
64
|
-
#Rename session key
|
65
|
-
replace_into_file('config/initializers/session_store.rb', /(('|")_.*_session('|"))/i, "'_#{@new_key}_session'")
|
66
|
-
#Rename database
|
67
|
-
replace_into_file('config/database.yml', /#{@old_module_name.underscore}/i, @new_name.underscore)
|
68
|
-
#Rename into channel and job queue
|
69
|
-
%w(config/cable.yml config/environments/production.rb).each do |file|
|
70
|
-
replace_into_file(file, /#{@old_module_name.underscore}_production/, "#{@new_module_name.underscore}_production")
|
71
|
-
end
|
72
|
-
#Application layout
|
73
|
-
%w(erb haml).each do |file|
|
74
|
-
replace_into_file("app/views/layouts/application.html.#{file}", /#{@old_module_name}/, @new_module_name)
|
75
|
-
end
|
76
|
-
# Update package.json name entry
|
77
|
-
old_package_name_regex = /\Wname\W *: *\W(?<name>[-_\p{Alnum}]+)\W *, */i
|
78
|
-
new_package_name = %("name":"#{@new_module_name.underscore}",)
|
79
|
-
replace_into_file('package.json', old_package_name_regex, new_package_name)
|
80
|
-
|
81
|
-
puts 'Search and replace module in environment variables...'
|
82
|
-
#Rename database
|
83
|
-
replace_into_file('config/database.yml', /#{@old_module_name.underscore.upcase}/, @new_module_name.underscore.upcase)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
# rename_app_to_new_app_directory
|
88
|
-
def change_app_directory
|
89
|
-
rename_references
|
90
|
-
rename_directory
|
91
|
-
end
|
92
|
-
|
93
|
-
private
|
94
|
-
|
95
|
-
def reserved_names
|
96
|
-
@reserved_names = %w[application destroy benchmarker profiler plugin runner test]
|
97
|
-
end
|
98
|
-
|
99
|
-
def
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module CommonMethods
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
desc 'Rename your Rails application'
|
8
|
+
|
9
|
+
argument :new_name, :type => :string, :default => ''
|
10
|
+
end
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def perform
|
15
|
+
prepare_app_vars
|
16
|
+
validate_name_and_path?
|
17
|
+
apply_new_module_name
|
18
|
+
change_app_directory
|
19
|
+
end
|
20
|
+
|
21
|
+
def app_parent
|
22
|
+
if Rails.version.to_f >= 3.3
|
23
|
+
Rails.application.class.to_s.deconstantize
|
24
|
+
else
|
25
|
+
Rails.application.class.parent.name
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def prepare_app_vars
|
30
|
+
@new_key = new_name.gsub(/\W/, '_')
|
31
|
+
@old_module_name = app_parent
|
32
|
+
@new_module_name = @new_key.squeeze('_').camelize
|
33
|
+
@new_dir = new_name.gsub(/[&%*@()!{}\[\]'\\\/"]+/, '')
|
34
|
+
@new_path = Rails.root.to_s.split('/')[0...-1].push(@new_dir).join('/')
|
35
|
+
end
|
36
|
+
|
37
|
+
def validate_name_and_path?
|
38
|
+
if new_name.blank?
|
39
|
+
raise Thor::Error, "[Error] Application name can't be blank."
|
40
|
+
elsif new_name =~ /^\d/
|
41
|
+
raise Thor::Error, '[Error] Please give a name which does not start with numbers.'
|
42
|
+
elsif @new_module_name.size < 1
|
43
|
+
raise Thor::Error, '[Error] Please enter at least one alphabet.'
|
44
|
+
elsif reserved_names.include?(@new_module_name.downcase)
|
45
|
+
raise Thor::Error, '[Error] Please give a name which does not match any of the reserved Rails keywords.'
|
46
|
+
elsif Object.const_defined?(@new_module_name)
|
47
|
+
raise Thor::Error, "[Error] Constant #{@new_module_name} is already in use, please choose another name."
|
48
|
+
elsif file_exist?(@new_path)
|
49
|
+
raise Thor::Error, '[Error] Already in use, please choose another name.'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# rename_app_to_new_app_module
|
54
|
+
def apply_new_module_name
|
55
|
+
in_root do
|
56
|
+
puts 'Search and replace module in files...'
|
57
|
+
|
58
|
+
#Search and replace module in to file
|
59
|
+
Dir['*', 'config/**/**/*.rb', '.{rvmrc}'].each do |file|
|
60
|
+
# file = File.join(Dir.pwd, file)
|
61
|
+
replace_into_file(file, /(#{@old_module_name}*)/m, @new_module_name)
|
62
|
+
end
|
63
|
+
|
64
|
+
#Rename session key
|
65
|
+
replace_into_file('config/initializers/session_store.rb', /(('|")_.*_session('|"))/i, "'_#{@new_key}_session'")
|
66
|
+
#Rename database
|
67
|
+
replace_into_file('config/database.yml', /#{@old_module_name.underscore}/i, @new_name.underscore)
|
68
|
+
#Rename into channel and job queue
|
69
|
+
%w(config/cable.yml config/environments/production.rb).each do |file|
|
70
|
+
replace_into_file(file, /#{@old_module_name.underscore}_production/, "#{@new_module_name.underscore}_production")
|
71
|
+
end
|
72
|
+
#Application layout
|
73
|
+
%w(erb haml).each do |file|
|
74
|
+
replace_into_file("app/views/layouts/application.html.#{file}", /#{@old_module_name}/, @new_module_name)
|
75
|
+
end
|
76
|
+
# Update package.json name entry
|
77
|
+
old_package_name_regex = /\Wname\W *: *\W(?<name>[-_\p{Alnum}]+)\W *, */i
|
78
|
+
new_package_name = %("name":"#{@new_module_name.underscore}",)
|
79
|
+
replace_into_file('package.json', old_package_name_regex, new_package_name)
|
80
|
+
|
81
|
+
puts 'Search and replace module in environment variables...'
|
82
|
+
#Rename database
|
83
|
+
replace_into_file('config/database.yml', /#{@old_module_name.underscore.upcase}/, @new_module_name.underscore.upcase)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# rename_app_to_new_app_directory
|
88
|
+
def change_app_directory
|
89
|
+
rename_references
|
90
|
+
rename_directory
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
def reserved_names
|
96
|
+
@reserved_names = %w[application destroy benchmarker profiler plugin runner test]
|
97
|
+
end
|
98
|
+
|
99
|
+
def file_exist?(name)
|
100
|
+
File.respond_to?(:exist?) ? File.exist?(name) : File.exists?(name)
|
101
|
+
end
|
102
|
+
|
103
|
+
def rename_references
|
104
|
+
puts 'Renaming references...'
|
105
|
+
old_basename = File.basename(Dir.getwd)
|
106
|
+
|
107
|
+
in_root do
|
108
|
+
Dir.glob('.idea/*', File::FNM_DOTMATCH).each do |file|
|
109
|
+
replace_into_file(file, old_basename, @new_dir)
|
110
|
+
end
|
111
|
+
|
112
|
+
gem_set_file = '.ruby-gemset'
|
113
|
+
replace_into_file(gem_set_file, old_basename, @new_dir) if file_exist?(gem_set_file)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def rename_directory
|
118
|
+
print 'Renaming directory...'
|
119
|
+
|
120
|
+
begin
|
121
|
+
# FileUtils.mv Dir.pwd, app_path
|
122
|
+
File.rename(Rails.root.to_s, @new_path)
|
123
|
+
puts 'Done!'
|
124
|
+
puts "New application path is '#{@new_path}'"
|
125
|
+
rescue Exception => ex
|
126
|
+
puts "Error:#{ex.inspect}"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def replace_into_file(file, search_exp, replace)
|
131
|
+
return if File.directory?(file) || !file_exist?(file)
|
132
|
+
|
133
|
+
begin
|
134
|
+
gsub_file file, search_exp, replace
|
135
|
+
rescue Exception => ex
|
136
|
+
puts "Error: #{ex.message}"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
data/lib/rename/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Rename
|
2
|
-
VERSION = '1.0.
|
3
|
-
end
|
1
|
+
module Rename
|
2
|
+
VERSION = '1.0.9'
|
3
|
+
end
|
data/rename.gemspec
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path('../lib/rename/version', __FILE__)
|
3
|
-
|
4
|
-
Gem::Specification.new do |gem|
|
5
|
-
gem.name = 'rename'
|
6
|
-
gem.version = Rename::VERSION
|
7
|
-
gem.license = 'MIT'
|
8
|
-
gem.authors = ['Morshed Alam']
|
9
|
-
gem.email = %w(morshed201@gmail.com)
|
10
|
-
gem.homepage = 'https://github.com/morshedalam/rename'
|
11
|
-
gem.summary = 'Rename your Rails application using a single command.'
|
12
|
-
|
13
|
-
gem.add_dependency 'rails', '>= 3.0.0'
|
14
|
-
gem.add_dependency 'thor', '>= 0.19.1'
|
15
|
-
gem.add_runtime_dependency 'activesupport'
|
16
|
-
gem.rubyforge_project = 'rename'
|
17
|
-
|
18
|
-
gem.files = `git ls-files`.split("\n")
|
19
|
-
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
20
|
-
gem.require_paths = %w(lib)
|
21
|
-
end
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/rename/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = 'rename'
|
6
|
+
gem.version = Rename::VERSION
|
7
|
+
gem.license = 'MIT'
|
8
|
+
gem.authors = ['Morshed Alam']
|
9
|
+
gem.email = %w(morshed201@gmail.com)
|
10
|
+
gem.homepage = 'https://github.com/morshedalam/rename'
|
11
|
+
gem.summary = 'Rename your Rails application using a single command.'
|
12
|
+
|
13
|
+
gem.add_dependency 'rails', '>= 3.0.0'
|
14
|
+
gem.add_dependency 'thor', '>= 0.19.1'
|
15
|
+
gem.add_runtime_dependency 'activesupport'
|
16
|
+
gem.rubyforge_project = 'rename'
|
17
|
+
|
18
|
+
gem.files = `git ls-files`.split("\n")
|
19
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
20
|
+
gem.require_paths = %w(lib)
|
21
|
+
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.0.
|
4
|
+
version: 1.0.9
|
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: 2024-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -94,7 +94,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
94
|
- !ruby/object:Gem::Version
|
95
95
|
version: '0'
|
96
96
|
requirements: []
|
97
|
-
|
97
|
+
rubyforge_project: rename
|
98
|
+
rubygems_version: 2.7.11
|
98
99
|
signing_key:
|
99
100
|
specification_version: 4
|
100
101
|
summary: Rename your Rails application using a single command.
|