rename 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/generators/rename/app_to/app_to_generator.rb +41 -33
- data/lib/rename/version.rb +1 -1
- metadata +10 -5
@@ -4,50 +4,58 @@ module Rename
|
|
4
4
|
argument :new_name, :type => :string, :default => "#{Rails.application.class.parent}"
|
5
5
|
|
6
6
|
def app_to
|
7
|
-
|
8
|
-
old_name = Regexp.escape("#{Rails.application.class.parent}")
|
9
|
-
rename_to = new_name.downcase.gsub(/\s/, "_").camelize.capitalize
|
10
|
-
new_root_directory = old_root_directory.gsub(/\/#{old_name.downcase}/, "/#{new_name.downcase}")
|
7
|
+
mod_name = new_name.gsub(/[^0-9A-Za-z]/, ' ').split(' ').map { |w| w.capitalize }.join('')
|
11
8
|
|
12
|
-
|
9
|
+
if mod_name.blank?
|
10
|
+
puts "Error:Invalid name"
|
11
|
+
return
|
12
|
+
end
|
13
|
+
|
14
|
+
new_module_name(mod_name)
|
15
|
+
new_directory_name(new_name)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def new_module_name(new_name)
|
20
|
+
search_exp = /(#{Regexp.escape("#{Rails.application.class.parent}")})/mi
|
13
21
|
|
14
|
-
#Inside the application
|
15
22
|
in_root do
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
#Search and replace in to root
|
24
|
+
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
|
+
|
29
|
+
#Search and replace under config
|
30
|
+
Dir["config/**/**/*.rb"].each do |file|
|
31
|
+
replace_module_in_file(file, search_exp, new_name)
|
25
32
|
end
|
26
33
|
end
|
27
|
-
puts "Renaming directory"
|
28
|
-
File.rename "#{old_root_directory}", "#{new_root_directory}"
|
29
34
|
end
|
30
35
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
['environments', /(#{old_name})(::Application.configure)/mi, "#{rename_to}::Application.configure"]
|
42
|
-
]
|
36
|
+
def replace_module_in_file(file, search_exp, module_name)
|
37
|
+
return if File.directory?(file)
|
38
|
+
|
39
|
+
begin
|
40
|
+
gsub_file file, search_exp do |m|
|
41
|
+
module_name
|
42
|
+
end
|
43
|
+
rescue Exception => ex
|
44
|
+
puts "Error:#{ex.message}"
|
45
|
+
end
|
43
46
|
end
|
44
47
|
|
45
|
-
def
|
46
|
-
|
47
|
-
|
48
|
+
def new_directory_name(new_name)
|
49
|
+
begin
|
50
|
+
print "Renaming directory..."
|
51
|
+
new_app_name = new_name.gsub(/[^0-9A-Za-z_]/, '-')
|
52
|
+
new_path = Rails.root.to_s.split('/')[0...-1].push(new_app_name).join('/')
|
53
|
+
File.rename(Rails.root.to_s, new_path)
|
54
|
+
puts "Done!"
|
55
|
+
rescue Exception => ex
|
56
|
+
puts "Error:#{ex.message}"
|
48
57
|
end
|
49
58
|
end
|
50
59
|
end
|
51
|
-
|
52
60
|
end
|
53
61
|
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.4
|
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: 2012-
|
12
|
+
date: 2012-11-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,12 @@ dependencies:
|
|
21
21
|
version: 3.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.0.0
|
25
30
|
description: This library allows you to rename Rails3 application by using a single
|
26
31
|
command
|
27
32
|
email:
|
@@ -62,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
67
|
version: '0'
|
63
68
|
requirements: []
|
64
69
|
rubyforge_project: rename
|
65
|
-
rubygems_version: 1.8.
|
70
|
+
rubygems_version: 1.8.24
|
66
71
|
signing_key:
|
67
72
|
specification_version: 3
|
68
73
|
summary: A library to rename your rails3 application
|