model_renamer 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/model_renamer/rename.rb +14 -11
- data/lib/model_renamer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3a829ecbbb9250b2dab972232984d45f61e4243
|
4
|
+
data.tar.gz: 96329fca0b7a2d690b2707090aef81b0337eb161
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f006580e6973f02dbf688df36d5aa4862b60e5b962e3bff167dc7cb3ef5f8666f7f341dc2ae14d12abd7113de5b5f45946707c30eda5e09533dc144162041688
|
7
|
+
data.tar.gz: 8b339a61d5bca5acb16cd9e2f328192055509ec46038ac8d22e890eb5ac52badfe42bcc13d31bba0067b80df0115b2e2dcd1c8909b4be58ff2845f0ad37df278
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# ModelRenamer
|
2
2
|
|
3
|
+
[![CircleCI](https://circleci.com/gh/viewthespace/model_renamer/tree/master.svg?style=svg)](https://circleci.com/gh/viewthespace/model_renamer/tree/master)
|
4
|
+
|
3
5
|
The model renamer gem allows you to rename any a model in your rails application. The gem looks for occurrences of any variation or pluralization of the old model name and changes it to the corresponding variation of the new name. It also generates database migrations that rename tables and foreign keys referencing the old name.
|
4
6
|
|
5
7
|
## Installation
|
data/lib/model_renamer/rename.rb
CHANGED
@@ -24,15 +24,15 @@ class Rename
|
|
24
24
|
generate_migrations
|
25
25
|
end
|
26
26
|
|
27
|
-
def rename_files_and_directories
|
28
|
-
Dir["#{
|
29
|
-
if File.directory?(
|
30
|
-
rename_files_and_directories
|
27
|
+
def rename_files_and_directories outer_path = @path
|
28
|
+
Dir["#{outer_path}/*"].reject { |path| ignore_file? path }.each do |inner_path|
|
29
|
+
if File.directory?(inner_path)
|
30
|
+
rename_files_and_directories inner_path
|
31
31
|
else
|
32
|
-
rename_path
|
32
|
+
rename_path inner_path
|
33
33
|
end
|
34
34
|
end
|
35
|
-
rename_path
|
35
|
+
rename_path outer_path
|
36
36
|
end
|
37
37
|
|
38
38
|
def rename_in_files
|
@@ -47,10 +47,13 @@ class Rename
|
|
47
47
|
|
48
48
|
private
|
49
49
|
|
50
|
-
def rename_path
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
def rename_path initial_filepath
|
51
|
+
current_filepath = initial_filepath
|
52
|
+
variation_pairs.uniq.each do |old_name, new_name|
|
53
|
+
next unless File.basename(current_filepath).include? old_name
|
54
|
+
new_filepath = File.dirname(current_filepath) + "/#{File.basename(current_filepath).gsub(old_name, new_name)}"
|
55
|
+
FileUtils.mv current_filepath, new_filepath
|
56
|
+
current_filepath = new_filepath
|
54
57
|
end
|
55
58
|
end
|
56
59
|
|
@@ -59,7 +62,7 @@ class Rename
|
|
59
62
|
end
|
60
63
|
|
61
64
|
def all_filepaths
|
62
|
-
Find.find(
|
65
|
+
Find.find(@path.presence || ".").to_a.reject do |path|
|
63
66
|
FileTest.directory?(path) || !acceptable_filetype?(path) || ignore_file?(path)
|
64
67
|
end
|
65
68
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: model_renamer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Gut
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|