rename 1.0.0 → 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ecbfa0a04554ccae51f941228ad689d8a2269da47c9160be9279b60b6fdc964e
4
+ data.tar.gz: 6b0c511c5bc94fa96bd866ed707857fc25afd7a038607ccb9d81d6cd15de95af
5
+ SHA512:
6
+ metadata.gz: 53282557f4f876b2fd3bbdfabc2adbc4546cffc516c09993c8226c3cbcba6d62a3316b032c921d70eef4f9b072d62ccd5036bd02c91f99389320b112cb5728f6
7
+ data.tar.gz: 96b728cc89e8c2e62900c3e63371601a905ef9ad3691d59983c5c9c11dc5fdf99f1f634ea59dc278bac80c2d500b7c1cf15552452147970736b39feaa0bb4fa5
data/README.md CHANGED
@@ -1,20 +1,22 @@
1
1
  # Rename
2
2
 
3
- This Gem allows you to rename a Rails3 application by using a single command.
3
+ This gem allows you to rename your Rails application by using a single command.
4
4
 
5
+ Tested up to Rails 6.1.
5
6
 
6
7
  ## Installation
7
8
 
8
9
  Add this line to your application's Gemfile:
9
10
 
10
- <pre><code>gem 'rename'</code></pre>
11
-
11
+ ```ruby
12
+ gem 'rename'
13
+ ```
12
14
 
13
15
  ## Usage
14
16
 
15
- <pre><code>rails g rename:app_to New-Name
16
- </code></pre>
17
-
17
+ ```
18
+ rails g rename:into New-Name
19
+ ```
18
20
 
19
21
 
20
22
  ## Contributing
data/TO DO ADDED
@@ -0,0 +1 @@
1
+ == Rename github repository using API
@@ -1 +1 @@
1
- rails g rename:app_to NewName
1
+ rails g rename:app_to NewName
@@ -1,94 +1,13 @@
1
+ require File.expand_path('../shared/common_methods', File.dirname(__FILE__))
2
+
1
3
  module Rename
2
4
  module Generators
3
5
  class AppToGenerator < Rails::Generators::Base
4
- argument :new_name, :type => :string
6
+ include CommonMethods
5
7
 
6
8
  def app_to
7
- return if !valid_app_name?
8
- new_module_name()
9
- new_basename()
10
- end
11
-
12
- private
13
-
14
- def valid_app_name?
15
- if new_name.to_s.strip.blank?
16
- puts "Please enter new application name"
17
- return false
18
- elsif new_name.match(/^[A-Za-z]/).nil?
19
- puts "Invalid application name"
20
- return false
21
- elsif new_name.size < 3
22
- puts "New application name too short"
23
- return false
24
- elsif new_name.scan(/[0-9A-Za-z]/).size < 3
25
- puts "Name should have minimum 3 alphanumeric characters"
26
- return false
27
- end
28
-
29
- return true
30
- end
31
-
32
- def new_module_name()
33
- search_exp = /(#{Regexp.escape("#{Rails.application.class.parent}")})/m
34
- module_name = new_name.gsub(/[^0-9A-Za-z]/, ' ').split(' ').map { |w| w.capitalize }.join('')
35
-
36
- in_root do
37
- puts "Search and Replace Module in to..."
38
-
39
- #Search and replace module in to file
40
- Dir["*", "config/**/**/*.rb", ".{rvmrc}"].each do |file|
41
- replace_into_file(file, search_exp, module_name)
42
- end
43
-
44
- #Rename session key
45
- session_key_file = 'config/initializers/session_store.rb'
46
- search_exp = /((\'|\")_.*_session(\'|\"))/i
47
- session_key = "'_#{module_name.gsub(/[^0-9A-Za-z_]/, '_').downcase}_session'"
48
- replace_into_file(session_key_file, search_exp, session_key)
49
- end
50
- end
51
-
52
- def new_basename()
53
- basename = new_name.gsub(/[^0-9A-Za-z_]/, '-')
54
- change_basename(basename)
55
- change_directory_name(basename)
56
- end
57
-
58
- def change_basename(basename)
59
- puts "Renaming basename..."
60
-
61
- old_basename = File.basename(Dir.getwd)
62
-
63
- in_root do
64
- Dir.glob(".idea/*", File::FNM_DOTMATCH).each do |file|
65
- replace_into_file(file, old_basename, basename)
66
- end
67
-
68
- gemset_file = ".ruby-gemset"
69
- replace_into_file(gemset_file, old_basename, basename) if File.exist?(gemset_file)
70
- end
71
- end
72
-
73
- def change_directory_name(basename)
74
- begin
75
- print "Renaming directory..."
76
- new_path = Rails.root.to_s.split('/')[0...-1].push(basename).join('/')
77
- File.rename(Rails.root.to_s, new_path)
78
- puts "Done!"
79
- rescue Exception => ex
80
- puts "Error:#{ex.message}"
81
- end
82
- end
83
-
84
- def replace_into_file(file, search_exp, replace)
85
- return if File.directory?(file)
86
-
87
- begin
88
- gsub_file file, search_exp, replace
89
- rescue Exception => ex
90
- puts "Error: #{ex.message}"
91
- end
9
+ warn '[DEPRECATION] `app_to` is deprecated. Please use `into` instead.'
10
+ perform
92
11
  end
93
12
  end
94
13
  end
@@ -0,0 +1 @@
1
+ rails g rename:into NewName
@@ -0,0 +1,13 @@
1
+ require File.expand_path('../shared/common_methods', File.dirname(__FILE__))
2
+
3
+ module Rename
4
+ module Generators
5
+ class IntoGenerator < Rails::Generators::Base
6
+ include CommonMethods
7
+
8
+ def into
9
+ perform
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +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 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
data/lib/rename.rb CHANGED
@@ -1 +1,3 @@
1
- require "rename/version"
1
+ module Rename
2
+ autoload :VERSION, 'active_admin/version'
3
+ end
@@ -1,3 +1,3 @@
1
- module Rename
2
- VERSION = "1.0.0"
3
- end
1
+ module Rename
2
+ VERSION = '1.0.8'
3
+ end
data/rename.gemspec CHANGED
@@ -1,19 +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.authors = ["Morshed Alam"]
8
- gem.email = ["morshed201@gmail.com"]
9
- gem.homepage = "https://github.com/morshedalam/rename"
10
- gem.description = 'This library allows you to rename Rails3 application by using a single command'
11
- gem.summary = 'A library to rename your rails3 application'
12
-
13
- gem.add_dependency "rails", ">= 3.0.0"
14
- gem.rubyforge_project = "rename"
15
-
16
- gem.files = `git ls-files`.split("\n")
17
- gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
- gem.require_paths = ["lib"]
19
- 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,69 +1,101 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rename
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 1.0.8
6
5
  platform: ruby
7
6
  authors:
8
7
  - Morshed Alam
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-06-25 00:00:00.000000000Z
11
+ date: 2021-07-05 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
16
- requirement: &72799420 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: 3.0.0
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *72799420
25
- description: This library allows you to rename Rails3 application by using a single
26
- command
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.19.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.19.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
27
56
  email:
28
57
  - morshed201@gmail.com
29
58
  executables: []
30
59
  extensions: []
31
60
  extra_rdoc_files: []
32
61
  files:
33
- - .gitignore
62
+ - ".gitignore"
34
63
  - Gemfile
35
64
  - LICENSE
36
65
  - README.md
37
66
  - Rakefile
67
+ - TO DO
38
68
  - lib/generators/rename/app_to/USAGE
39
69
  - lib/generators/rename/app_to/app_to_generator.rb
70
+ - lib/generators/rename/into/USAGE
71
+ - lib/generators/rename/into/into_generator.rb
72
+ - lib/generators/rename/shared/common_methods.rb
40
73
  - lib/rename.rb
41
74
  - lib/rename/version.rb
42
75
  - rename.gemspec
43
76
  - tests/rename_test.rb
44
77
  - tests/test_helper.rb
45
78
  homepage: https://github.com/morshedalam/rename
46
- licenses: []
47
- post_install_message:
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
48
83
  rdoc_options: []
49
84
  require_paths:
50
85
  - lib
51
86
  required_ruby_version: !ruby/object:Gem::Requirement
52
- none: false
53
87
  requirements:
54
- - - ! '>='
88
+ - - ">="
55
89
  - !ruby/object:Gem::Version
56
90
  version: '0'
57
91
  required_rubygems_version: !ruby/object:Gem::Requirement
58
- none: false
59
92
  requirements:
60
- - - ! '>='
93
+ - - ">="
61
94
  - !ruby/object:Gem::Version
62
95
  version: '0'
63
96
  requirements: []
64
- rubyforge_project: rename
65
- rubygems_version: 1.7.2
66
- signing_key:
67
- specification_version: 3
68
- summary: A library to rename your rails3 application
97
+ rubygems_version: 3.0.3
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Rename your Rails application using a single command.
69
101
  test_files: []