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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ecbfa0a04554ccae51f941228ad689d8a2269da47c9160be9279b60b6fdc964e
4
- data.tar.gz: 6b0c511c5bc94fa96bd866ed707857fc25afd7a038607ccb9d81d6cd15de95af
3
+ metadata.gz: 59dcefa0ad39fd863840b89bfaa4b6d79395009d63c489243fbea126496a901a
4
+ data.tar.gz: 3125cd4d95bb1d153ae31f2c6e21e8a6cce0232ccbe7d3115307de3215a5bb2f
5
5
  SHA512:
6
- metadata.gz: 53282557f4f876b2fd3bbdfabc2adbc4546cffc516c09993c8226c3cbcba6d62a3316b032c921d70eef4f9b072d62ccd5036bd02c91f99389320b112cb5728f6
7
- data.tar.gz: 96b728cc89e8c2e62900c3e63371601a905ef9ad3691d59983c5c9c11dc5fdf99f1f634ea59dc278bac80c2d500b7c1cf15552452147970736b39feaa0bb4fa5
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 File.exists?(@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 rename_references
100
- puts 'Renaming references...'
101
- old_basename = File.basename(Dir.getwd)
102
-
103
- in_root do
104
- Dir.glob('.idea/*', File::FNM_DOTMATCH).each do |file|
105
- replace_into_file(file, old_basename, @new_dir)
106
- end
107
-
108
- gem_set_file = '.ruby-gemset'
109
- replace_into_file(gem_set_file, old_basename, @new_dir) if File.exist?(gem_set_file)
110
- end
111
- end
112
-
113
- def rename_directory
114
- print 'Renaming directory...'
115
-
116
- begin
117
- # FileUtils.mv Dir.pwd, app_path
118
- File.rename(Rails.root.to_s, @new_path)
119
- puts 'Done!'
120
- puts "New application path is '#{@new_path}'"
121
- rescue Exception => ex
122
- puts "Error:#{ex.inspect}"
123
- end
124
- end
125
-
126
- def replace_into_file(file, search_exp, replace)
127
- return if File.directory?(file) || !File.exists?(file)
128
-
129
- begin
130
- gsub_file file, search_exp, replace
131
- rescue Exception => ex
132
- puts "Error: #{ex.message}"
133
- end
134
- end
135
- end
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
@@ -1,3 +1,3 @@
1
- module Rename
2
- VERSION = '1.0.8'
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.8
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: 2021-07-05 00:00:00.000000000 Z
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
- rubygems_version: 3.0.3
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.