rename 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- old_root_directory = "#{Rails.root}"
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
- changes = list_of_changes(rename_to, old_name)
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
- for change in changes
17
- if change[0] == 'environments'
18
- for env_name in ['development', 'production', 'test']
19
- change[0] = "config/environments/#{env_name}.rb"
20
- replace_on_file(change)
21
- end
22
- else
23
- replace_on_file(change)
24
- end
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
- private
32
- def list_of_changes(rename_to, old_name)
33
- return [
34
- ['Rakefile', /(#{old_name})(::Application.load_tasks)/mi, "#{rename_to}::Application.load_tasks"],
35
- ['config.ru', /(run) (#{old_name})(::Application)/mi, "run #{rename_to}::Application"],
36
- ['config/routes.rb', /(#{old_name})(::Application.routes)/mi, "#{rename_to}::Application.routes"],
37
- ['config/application.rb', /(module) (#{old_name})/mi, "module #{rename_to}"],
38
- ['config/environment.rb', /(#{old_name})(::Application.initialize!)/mi, "#{rename_to}::Application.initialize!"],
39
- ['config/initializers/secret_token.rb', /(#{old_name})(::Application.config.secret_token)/mi, "#{rename_to}::Application.config.secret_token"],
40
- ['config/initializers/session_store.rb', /(#{old_name})(::Application.config.session_store)/mi, "#{rename_to}::Application.config.session_store"],
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 replace_on_file(change)
46
- gsub_file change[0], change[1] do |match|
47
- change[2]
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
@@ -1,3 +1,3 @@
1
1
  module Rename
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
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.3
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-04-08 00:00:00.000000000 Z
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: &80917380 !ruby/object:Gem::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: *80917380
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.17
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