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 CHANGED
@@ -12,8 +12,7 @@ Add this line to your application's Gemfile:
12
12
 
13
13
  ## Usage
14
14
 
15
- <pre><code>rails g rename:app_to NewName
16
- rails g rename:app_to "New-Name"
15
+ <pre><code>rails g rename:app_to New-Name
17
16
  </code></pre>
18
17
 
19
18
 
@@ -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, :default => "#{Rails.application.class.parent}"
4
+ argument :new_name, :type => :string
5
5
 
6
6
  def app_to
7
- mod_name = new_name.gsub(/[^0-9A-Za-z]/, ' ').split(' ').map { |w| w.capitalize }.join('')
7
+ return if !valid_app_name?
8
+ new_module_name()
9
+ new_basename()
10
+ end
11
+
12
+ private
8
13
 
9
- if mod_name.blank?
10
- puts "Error:Invalid name"
11
- return
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
- new_module_name(mod_name)
15
- new_directory_name(new_name)
29
+ return true
16
30
  end
17
31
 
18
- private
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 under config
30
- Dir["config/**/**/*.rb"].each do |file|
31
- replace_module_in_file(file, search_exp, new_name)
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 = "'_#{new_name.gsub(/[^0-9A-Za-z_]/, '_').downcase}_session'"
38
- replace_module_in_file(session_key_file, search_exp, session_key)
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 replace_module_in_file(file, search_exp, module_name)
43
- return if File.directory?(file)
52
+ def new_basename()
53
+ basename = new_name.gsub(/[^0-9A-Za-z_]/, '-')
44
54
 
45
- begin
46
- gsub_file file, search_exp do |m|
47
- module_name
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
- rescue Exception => ex
50
- puts "Error:#{ex.message}"
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 new_directory_name(new_name)
73
+ def change_directory_name(basename)
55
74
  begin
56
75
  print "Renaming directory..."
57
- new_app_name = new_name.gsub(/[^0-9A-Za-z_]/, '-')
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
@@ -1,3 +1,3 @@
1
1
  module Rename
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.8"
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.6
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-01-20 00:00:00.000000000Z
12
+ date: 2013-06-02 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &72624310 !ruby/object:Gem::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: *72624310
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: