rename 1.0.6 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
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: 59dcefa0ad39fd863840b89bfaa4b6d79395009d63c489243fbea126496a901a
4
+ data.tar.gz: 3125cd4d95bb1d153ae31f2c6e21e8a6cce0232ccbe7d3115307de3215a5bb2f
5
5
  SHA512:
6
- metadata.gz: 36e829ddf323a7a23bd4dced6a25235f349f3c4e882cf10c1b0cb5c786722f4810da9743cb979adea97ad7937fdc881d3453a8bd1f4c71c6735a8d2d9ad318b1
7
- data.tar.gz: 258e8c04b94ed48517ae37c65e283e0c680c2cce8b66ccccc646742a07aec49946032744fb7c25febbb7f100ecde3d7dd6e876778cbb57a5ce87d0a142a1a988
6
+ metadata.gz: fc304eb7f357c6b8adc6ed8daefd10460c417df186050574035b4c63ea7ede4a555fff2e1355cf4e6e03d7e4459c88a6ba7b980acebe4b4b18c5b1cdd8848bb1
7
+ data.tar.gz: 7af04e3ac1bfb29ca8596d40dfad2434ccc4578d16a53d8bc3d1edaedb4f9b464171fdde8fa924891d99afa7da6612ebbca1c9486948f7cd342b68867c232918
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
 
@@ -18,9 +18,17 @@ module CommonMethods
18
18
  change_app_directory
19
19
  end
20
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
+
21
29
  def prepare_app_vars
22
30
  @new_key = new_name.gsub(/\W/, '_')
23
- @old_module_name = Rails.application.class.parent.to_s
31
+ @old_module_name = app_parent
24
32
  @new_module_name = @new_key.squeeze('_').camelize
25
33
  @new_dir = new_name.gsub(/[&%*@()!{}\[\]'\\\/"]+/, '')
26
34
  @new_path = Rails.root.to_s.split('/')[0...-1].push(@new_dir).join('/')
@@ -37,7 +45,7 @@ module CommonMethods
37
45
  raise Thor::Error, '[Error] Please give a name which does not match any of the reserved Rails keywords.'
38
46
  elsif Object.const_defined?(@new_module_name)
39
47
  raise Thor::Error, "[Error] Constant #{@new_module_name} is already in use, please choose another name."
40
- elsif File.exists?(@new_path)
48
+ elsif file_exist?(@new_path)
41
49
  raise Thor::Error, '[Error] Already in use, please choose another name.'
42
50
  end
43
51
  end
@@ -45,7 +53,7 @@ module CommonMethods
45
53
  # rename_app_to_new_app_module
46
54
  def apply_new_module_name
47
55
  in_root do
48
- puts 'Search and replace module in...'
56
+ puts 'Search and replace module in files...'
49
57
 
50
58
  #Search and replace module in to file
51
59
  Dir['*', 'config/**/**/*.rb', '.{rvmrc}'].each do |file|
@@ -57,6 +65,22 @@ module CommonMethods
57
65
  replace_into_file('config/initializers/session_store.rb', /(('|")_.*_session('|"))/i, "'_#{@new_key}_session'")
58
66
  #Rename database
59
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)
60
84
  end
61
85
  end
62
86
 
@@ -72,6 +96,10 @@ module CommonMethods
72
96
  @reserved_names = %w[application destroy benchmarker profiler plugin runner test]
73
97
  end
74
98
 
99
+ def file_exist?(name)
100
+ File.respond_to?(:exist?) ? File.exist?(name) : File.exists?(name)
101
+ end
102
+
75
103
  def rename_references
76
104
  puts 'Renaming references...'
77
105
  old_basename = File.basename(Dir.getwd)
@@ -82,7 +110,7 @@ module CommonMethods
82
110
  end
83
111
 
84
112
  gem_set_file = '.ruby-gemset'
85
- replace_into_file(gem_set_file, old_basename, @new_dir) if File.exist?(gem_set_file)
113
+ replace_into_file(gem_set_file, old_basename, @new_dir) if file_exist?(gem_set_file)
86
114
  end
87
115
  end
88
116
 
@@ -100,7 +128,7 @@ module CommonMethods
100
128
  end
101
129
 
102
130
  def replace_into_file(file, search_exp, replace)
103
- return if File.directory?(file)
131
+ return if File.directory?(file) || !file_exist?(file)
104
132
 
105
133
  begin
106
134
  gsub_file file, search_exp, replace
@@ -1,3 +1,3 @@
1
1
  module Rename
2
- VERSION = '1.0.6'
2
+ VERSION = '1.0.9'
3
3
  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.9
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: 2024-04-07 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
@@ -95,8 +95,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  version: '0'
96
96
  requirements: []
97
97
  rubyforge_project: rename
98
- rubygems_version: 2.5.1
99
- signing_key:
98
+ rubygems_version: 2.7.11
99
+ signing_key:
100
100
  specification_version: 4
101
101
  summary: Rename your Rails application using a single command.
102
102
  test_files: []