rename 0.0.6 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -2
- data/lib/generators/rename/app_to/app_to_generator.rb +56 -29
- data/lib/rename/version.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -1,67 +1,94 @@
|
|
1
1
|
module Rename
|
2
2
|
module Generators
|
3
3
|
class AppToGenerator < Rails::Generators::Base
|
4
|
-
argument :new_name, :type => :string
|
4
|
+
argument :new_name, :type => :string
|
5
5
|
|
6
6
|
def app_to
|
7
|
-
|
7
|
+
return if !valid_app_name?
|
8
|
+
new_module_name()
|
9
|
+
new_basename()
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
8
13
|
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
12
27
|
end
|
13
28
|
|
14
|
-
|
15
|
-
new_directory_name(new_name)
|
29
|
+
return true
|
16
30
|
end
|
17
31
|
|
18
|
-
|
19
|
-
def new_module_name(new_name)
|
32
|
+
def new_module_name()
|
20
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('')
|
21
35
|
|
22
36
|
in_root do
|
23
|
-
#Search and replace in to root
|
24
37
|
puts "Search and Replace Module in to..."
|
25
|
-
Dir["*"].each do |file|
|
26
|
-
replace_module_in_file(file, search_exp, new_name)
|
27
|
-
end
|
28
38
|
|
29
|
-
#Search and replace
|
30
|
-
Dir["config/**/**/*.rb"].each do |file|
|
31
|
-
|
39
|
+
#Search and replace module in to file
|
40
|
+
Dir["*", "config/**/**/*.rb", ".{rvmrc}"].each do |file|
|
41
|
+
search_and_replace_module_into_file(file, search_exp, module_name)
|
32
42
|
end
|
33
43
|
|
34
44
|
#Rename session key
|
35
45
|
session_key_file = 'config/initializers/session_store.rb'
|
36
46
|
search_exp = /((\'|\")_.*_session(\'|\"))/i
|
37
|
-
session_key = "'_#{
|
38
|
-
|
47
|
+
session_key = "'_#{module_name.gsub(/[^0-9A-Za-z_]/, '_').downcase}_session'"
|
48
|
+
search_and_replace_module_into_file(session_key_file, search_exp, session_key)
|
39
49
|
end
|
40
50
|
end
|
41
51
|
|
42
|
-
def
|
43
|
-
|
52
|
+
def new_basename()
|
53
|
+
basename = new_name.gsub(/[^0-9A-Za-z_]/, '-')
|
44
54
|
|
45
|
-
|
46
|
-
|
47
|
-
|
55
|
+
change_basename(basename)
|
56
|
+
change_directory_name(basename)
|
57
|
+
|
58
|
+
puts "Done!"
|
59
|
+
end
|
60
|
+
|
61
|
+
def change_basename(basename)
|
62
|
+
puts "Renaming basename..."
|
63
|
+
|
64
|
+
in_root do
|
65
|
+
Dir.glob(".idea/*", File::FNM_DOTMATCH).each do |file|
|
66
|
+
search_and_replace_module_into_file(file, File.basename(Dir.getwd), basename)
|
48
67
|
end
|
49
|
-
|
50
|
-
|
68
|
+
|
69
|
+
search_and_replace_module_into_file(".ruby-gemset", File.basename(Dir.getwd), basename)
|
51
70
|
end
|
52
71
|
end
|
53
72
|
|
54
|
-
def
|
73
|
+
def change_directory_name(basename)
|
55
74
|
begin
|
56
75
|
print "Renaming directory..."
|
57
|
-
|
58
|
-
new_path = Rails.root.to_s.split('/')[0...-1].push(new_app_name).join('/')
|
76
|
+
new_path = Rails.root.to_s.split('/')[0...-1].push(basename).join('/')
|
59
77
|
File.rename(Rails.root.to_s, new_path)
|
60
|
-
puts "Done!"
|
61
78
|
rescue Exception => ex
|
62
79
|
puts "Error:#{ex.message}"
|
63
80
|
end
|
64
81
|
end
|
82
|
+
|
83
|
+
def search_and_replace_module_into_file(file, search_exp, new_module_name)
|
84
|
+
return if File.directory?(file)
|
85
|
+
|
86
|
+
begin
|
87
|
+
gsub_file file, search_exp, new_module_name
|
88
|
+
rescue Exception => ex
|
89
|
+
puts "Error: #{ex.message}"
|
90
|
+
end
|
91
|
+
end
|
65
92
|
end
|
66
93
|
end
|
67
94
|
end
|
data/lib/rename/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rename
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-06-02 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &75130420 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 3.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *75130420
|
25
25
|
description: This library allows you to rename Rails3 application by using a single
|
26
26
|
command
|
27
27
|
email:
|