rename 1.0.6 → 1.0.8

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
- SHA1:
3
- metadata.gz: 19439c87fdb54c385c6e0e2dee31e1afd9c49fd3
4
- data.tar.gz: 11866da9e6216a796539a354cf62cd482a739b92
2
+ SHA256:
3
+ metadata.gz: ecbfa0a04554ccae51f941228ad689d8a2269da47c9160be9279b60b6fdc964e
4
+ data.tar.gz: 6b0c511c5bc94fa96bd866ed707857fc25afd7a038607ccb9d81d6cd15de95af
5
5
  SHA512:
6
- metadata.gz: 36e829ddf323a7a23bd4dced6a25235f349f3c4e882cf10c1b0cb5c786722f4810da9743cb979adea97ad7937fdc881d3453a8bd1f4c71c6735a8d2d9ad318b1
7
- data.tar.gz: 258e8c04b94ed48517ae37c65e283e0c680c2cce8b66ccccc646742a07aec49946032744fb7c25febbb7f100ecde3d7dd6e876778cbb57a5ce87d0a142a1a988
6
+ metadata.gz: 53282557f4f876b2fd3bbdfabc2adbc4546cffc516c09993c8226c3cbcba6d62a3316b032c921d70eef4f9b072d62ccd5036bd02c91f99389320b112cb5728f6
7
+ data.tar.gz: 96b728cc89e8c2e62900c3e63371601a905ef9ad3691d59983c5c9c11dc5fdf99f1f634ea59dc278bac80c2d500b7c1cf15552452147970736b39feaa0bb4fa5
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 Rails 5.
5
+ Tested up to Rails 6.1.
6
6
 
7
7
  ## Installation
8
8
 
@@ -1,111 +1,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 prepare_app_vars
22
- @new_key = new_name.gsub(/\W/, '_')
23
- @old_module_name = Rails.application.class.parent.to_s
24
- @new_module_name = @new_key.squeeze('_').camelize
25
- @new_dir = new_name.gsub(/[&%*@()!{}\[\]'\\\/"]+/, '')
26
- @new_path = Rails.root.to_s.split('/')[0...-1].push(@new_dir).join('/')
27
- end
28
-
29
- def validate_name_and_path?
30
- if new_name.blank?
31
- raise Thor::Error, "[Error] Application name can't be blank."
32
- elsif new_name =~ /^\d/
33
- raise Thor::Error, '[Error] Please give a name which does not start with numbers.'
34
- elsif @new_module_name.size < 1
35
- raise Thor::Error, '[Error] Please enter at least one alphabet.'
36
- elsif reserved_names.include?(@new_module_name.downcase)
37
- raise Thor::Error, '[Error] Please give a name which does not match any of the reserved Rails keywords.'
38
- elsif Object.const_defined?(@new_module_name)
39
- raise Thor::Error, "[Error] Constant #{@new_module_name} is already in use, please choose another name."
40
- elsif File.exists?(@new_path)
41
- raise Thor::Error, '[Error] Already in use, please choose another name.'
42
- end
43
- end
44
-
45
- # rename_app_to_new_app_module
46
- def apply_new_module_name
47
- in_root do
48
- puts 'Search and replace module in...'
49
-
50
- #Search and replace module in to file
51
- Dir['*', 'config/**/**/*.rb', '.{rvmrc}'].each do |file|
52
- # file = File.join(Dir.pwd, file)
53
- replace_into_file(file, /(#{@old_module_name}*)/m, @new_module_name)
54
- end
55
-
56
- #Rename session key
57
- replace_into_file('config/initializers/session_store.rb', /(('|")_.*_session('|"))/i, "'_#{@new_key}_session'")
58
- #Rename database
59
- replace_into_file('config/database.yml', /#{@old_module_name.underscore}/i, @new_name.underscore)
60
- end
61
- end
62
-
63
- # rename_app_to_new_app_directory
64
- def change_app_directory
65
- rename_references
66
- rename_directory
67
- end
68
-
69
- private
70
-
71
- def reserved_names
72
- @reserved_names = %w[application destroy benchmarker profiler plugin runner test]
73
- end
74
-
75
- def rename_references
76
- puts 'Renaming references...'
77
- old_basename = File.basename(Dir.getwd)
78
-
79
- in_root do
80
- Dir.glob('.idea/*', File::FNM_DOTMATCH).each do |file|
81
- replace_into_file(file, old_basename, @new_dir)
82
- end
83
-
84
- gem_set_file = '.ruby-gemset'
85
- replace_into_file(gem_set_file, old_basename, @new_dir) if File.exist?(gem_set_file)
86
- end
87
- end
88
-
89
- def rename_directory
90
- print 'Renaming directory...'
91
-
92
- begin
93
- # FileUtils.mv Dir.pwd, app_path
94
- File.rename(Rails.root.to_s, @new_path)
95
- puts 'Done!'
96
- puts "New application path is '#{@new_path}'"
97
- rescue Exception => ex
98
- puts "Error:#{ex.inspect}"
99
- end
100
- end
101
-
102
- def replace_into_file(file, search_exp, replace)
103
- return if File.directory?(file)
104
-
105
- begin
106
- gsub_file file, search_exp, replace
107
- rescue Exception => ex
108
- puts "Error: #{ex.message}"
109
- end
110
- end
111
- 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.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,3 +1,3 @@
1
- module Rename
2
- VERSION = '1.0.6'
3
- end
1
+ module Rename
2
+ VERSION = '1.0.8'
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.6
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Morshed Alam
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-23 00:00:00.000000000 Z
11
+ date: 2021-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description:
55
+ description:
56
56
  email:
57
57
  - morshed201@gmail.com
58
58
  executables: []
@@ -79,7 +79,7 @@ homepage: https://github.com/morshedalam/rename
79
79
  licenses:
80
80
  - MIT
81
81
  metadata: {}
82
- post_install_message:
82
+ post_install_message:
83
83
  rdoc_options: []
84
84
  require_paths:
85
85
  - lib
@@ -94,9 +94,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  - !ruby/object:Gem::Version
95
95
  version: '0'
96
96
  requirements: []
97
- rubyforge_project: rename
98
- rubygems_version: 2.5.1
99
- signing_key:
97
+ rubygems_version: 3.0.3
98
+ signing_key:
100
99
  specification_version: 4
101
100
  summary: Rename your Rails application using a single command.
102
101
  test_files: []