model_renamer 0.1.5 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.circleci/config.yml +32 -0
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -5
- data/README.md +23 -3
- data/lib/model_renamer/migration_generator.rb +1 -1
- data/lib/model_renamer/rename.rb +41 -30
- data/lib/model_renamer/version.rb +1 -1
- data/model_renamer.gemspec +6 -0
- metadata +91 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5e42b0a3bfd2fe82b23f951f1a15062ac0c8f29
|
4
|
+
data.tar.gz: c1f5b417f6a45de0a8eff12be12c6e49aa315c7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f24bcc31fbec3936c37fc40e36c1f17fa2c836ca2ff5136a032236c041a359ade986f328f2ca551be1785e729fb90f0b814f08907d154c99436cddca35710d4
|
7
|
+
data.tar.gz: 88486ac6e04529429322a417f7b0222c5453224e1f2a7545b33837d83c6b46e0790ac5fca924d4f7e46fc657a55f066e03c1a8c1295a267f59be22073e215ec0
|
@@ -0,0 +1,32 @@
|
|
1
|
+
version: 2
|
2
|
+
jobs:
|
3
|
+
build:
|
4
|
+
docker:
|
5
|
+
- image: circleci/ruby:2.4.1-node-browsers
|
6
|
+
steps:
|
7
|
+
- checkout
|
8
|
+
- restore_cache:
|
9
|
+
keys:
|
10
|
+
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
11
|
+
# fallback to using the latest cache if no exact match is found
|
12
|
+
- v1-dependencies-
|
13
|
+
- run:
|
14
|
+
name: install dependencies
|
15
|
+
command: |
|
16
|
+
gem install bundler
|
17
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
18
|
+
- save_cache:
|
19
|
+
paths:
|
20
|
+
- ./vendor/bundle
|
21
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
22
|
+
|
23
|
+
- run:
|
24
|
+
name: run tests
|
25
|
+
command: |
|
26
|
+
mkdir /tmp/test-results
|
27
|
+
bundle exec rspec
|
28
|
+
- store_test_results:
|
29
|
+
path: /tmp/test-results
|
30
|
+
- store_artifacts:
|
31
|
+
path: /tmp/test-results
|
32
|
+
destination: test-results
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
model_renamer
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.1
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -23,13 +23,19 @@ Or install it yourself as:
|
|
23
23
|
Run rails console and use the following command:
|
24
24
|
|
25
25
|
```ruby
|
26
|
-
Rename.new("OldName", "NewName").
|
26
|
+
Rename.new("OldName", "NewName").run
|
27
27
|
```
|
28
28
|
|
29
|
-
This will rename everything in the codebase as well as generate the migrations. If you only want to rename
|
29
|
+
This will rename everything in the codebase as well as generate the migrations. If you only want to rename files and directories, run:
|
30
30
|
|
31
31
|
```ruby
|
32
|
-
Rename.new("OldName", "NewName").
|
32
|
+
Rename.new("OldName", "NewName").rename_files_and_directories
|
33
|
+
```
|
34
|
+
|
35
|
+
To only rename within the contents of the files, run:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
Rename.new("OldName", "NewName").rename_in_files
|
33
39
|
```
|
34
40
|
|
35
41
|
To only generate migrations, you guessed it:
|
@@ -37,3 +43,17 @@ To only generate migrations, you guessed it:
|
|
37
43
|
```ruby
|
38
44
|
Rename.new("OldName", "NewName").generate_migrations
|
39
45
|
```
|
46
|
+
|
47
|
+
## Options
|
48
|
+
|
49
|
+
You can pass in parameters to the constructor to specify paths to ignore and the root directory:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
Rename.new("OldName", "NewName", ignore_paths: ['mailers/'], path: 'app/')
|
53
|
+
```
|
54
|
+
|
55
|
+
This will ignore any files within the `mailers/` directory and search for `OldName` renames starting in the `app/` directory. By default no paths are ignored and the path is the current directory.
|
56
|
+
|
57
|
+
## Supported File Types
|
58
|
+
|
59
|
+
These are the file types that renamer will search for: `js, coffee, hamlc, skim, erb, sass, scss, css, rb, slim, haml, rabl, html, txt, feature, rake, json, sh, yaml, yml, sql, csv`
|
@@ -11,7 +11,7 @@ class MigrationGenerator
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def create_migration_file
|
14
|
-
path = Rails::Generators.invoke("active_record:migration", [migration_name])[
|
14
|
+
path = Rails::Generators.invoke("active_record:migration", [migration_name])[0]
|
15
15
|
File.write(path, migration_file_content)
|
16
16
|
end
|
17
17
|
|
data/lib/model_renamer/rename.rb
CHANGED
@@ -3,18 +3,42 @@
|
|
3
3
|
# then to create new directories and rename files. Then uses MigrationGenerator to create a migration
|
4
4
|
#
|
5
5
|
class Rename
|
6
|
+
ACCEPTABLE_FILE_TYPES = [
|
7
|
+
'js', 'coffee', 'hamlc', 'skim', 'erb',
|
8
|
+
'sass', 'scss', 'css', 'rb', 'slim',
|
9
|
+
'haml', 'rabl', 'html', 'txt', 'feature',
|
10
|
+
'rake', 'json', 'sh', 'yaml', 'sql', 'yml', 'csv'
|
11
|
+
].map(&:freeze)
|
6
12
|
|
7
|
-
|
13
|
+
DEFAULT_PATH = '.'
|
14
|
+
|
15
|
+
def initialize old_name, new_name, ignore_paths: [], path: DEFAULT_PATH
|
8
16
|
@variations_generator = VariationsGenerator.new(old_name, new_name)
|
17
|
+
@ignore_paths = ignore_paths
|
18
|
+
@path = path
|
9
19
|
end
|
10
20
|
|
11
|
-
def
|
12
|
-
|
21
|
+
def run
|
22
|
+
rename_files_and_directories @path
|
23
|
+
rename_in_files
|
13
24
|
generate_migrations
|
14
25
|
end
|
15
26
|
|
16
|
-
def
|
17
|
-
|
27
|
+
def rename_files_and_directories path = @path
|
28
|
+
Dir["#{path}/*"].reject { |path| ignore_file? path }.each do |path|
|
29
|
+
if File.directory?(path)
|
30
|
+
rename_files_and_directories path
|
31
|
+
else
|
32
|
+
rename_path path
|
33
|
+
end
|
34
|
+
end
|
35
|
+
rename_path path
|
36
|
+
end
|
37
|
+
|
38
|
+
def rename_in_files
|
39
|
+
all_filepaths.each do |filepath|
|
40
|
+
replace_all_variations_in_file filepath
|
41
|
+
end
|
18
42
|
end
|
19
43
|
|
20
44
|
def generate_migrations
|
@@ -23,10 +47,10 @@ class Rename
|
|
23
47
|
|
24
48
|
private
|
25
49
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
|
50
|
+
def rename_path filepath
|
51
|
+
variation_pairs.each do |old_name, new_name|
|
52
|
+
next unless File.basename(filepath).include? old_name
|
53
|
+
FileUtils.mv filepath, File.dirname(filepath) + "/#{File.basename(filepath).gsub(old_name, new_name)}"
|
30
54
|
end
|
31
55
|
end
|
32
56
|
|
@@ -36,17 +60,18 @@ class Rename
|
|
36
60
|
|
37
61
|
def all_filepaths
|
38
62
|
Find.find('.').to_a.reject do |path|
|
39
|
-
FileTest.directory?(path) || !acceptable_filetype?(path)
|
63
|
+
FileTest.directory?(path) || !acceptable_filetype?(path) || ignore_file?(path)
|
40
64
|
end
|
41
65
|
end
|
42
66
|
|
43
67
|
def acceptable_filetype? path
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
68
|
+
ACCEPTABLE_FILE_TYPES.include? path.split('.').last
|
69
|
+
end
|
70
|
+
|
71
|
+
def ignore_file? path
|
72
|
+
@ignore_paths.any? do |ignore_path|
|
73
|
+
path.include? ignore_path
|
74
|
+
end
|
50
75
|
end
|
51
76
|
|
52
77
|
def replace_all_variations_in_file filepath
|
@@ -62,18 +87,4 @@ class Rename
|
|
62
87
|
File.open(filepath, "w") { |file| file.puts new_text }
|
63
88
|
end
|
64
89
|
end
|
65
|
-
|
66
|
-
def rename_file filepath
|
67
|
-
variation_pairs.each do |variation|
|
68
|
-
create_directory filepath, variation[0], variation[1]
|
69
|
-
File.rename(filepath, filepath.gsub(variation[0], variation[1])) if File.file?(filepath)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def create_directory filepath, old_name, new_name
|
74
|
-
if File.dirname(filepath).include? old_name
|
75
|
-
FileUtils.mkdir_p File.dirname(filepath).gsub(old_name, new_name)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
90
|
end
|
data/model_renamer.gemspec
CHANGED
@@ -26,4 +26,10 @@ Gem::Specification.new do |spec|
|
|
26
26
|
|
27
27
|
spec.add_development_dependency "bundler", "~> 1.9"
|
28
28
|
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec"
|
30
|
+
spec.add_development_dependency "memfs"
|
31
|
+
spec.add_development_dependency "pry-byebug"
|
32
|
+
spec.add_dependency "activerecord"
|
33
|
+
spec.add_dependency "activesupport"
|
34
|
+
spec.add_dependency "rails"
|
29
35
|
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: 0.
|
4
|
+
version: 1.0.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: 2017-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,90 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: memfs
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: activerecord
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: activesupport
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rails
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
41
125
|
description: The model renamer gem allows you to rename any a model in your rails
|
42
126
|
application. The gem looks for occurrences of any variation or pluralization of
|
43
127
|
the old model name and changes it to the corresponding variation of the new name.
|
@@ -49,7 +133,11 @@ executables: []
|
|
49
133
|
extensions: []
|
50
134
|
extra_rdoc_files: []
|
51
135
|
files:
|
136
|
+
- ".circleci/config.yml"
|
52
137
|
- ".gitignore"
|
138
|
+
- ".rspec"
|
139
|
+
- ".ruby-gemset"
|
140
|
+
- ".ruby-version"
|
53
141
|
- Gemfile
|
54
142
|
- LICENSE.txt
|
55
143
|
- README.md
|
@@ -80,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
168
|
version: '0'
|
81
169
|
requirements: []
|
82
170
|
rubyforge_project:
|
83
|
-
rubygems_version: 2.
|
171
|
+
rubygems_version: 2.6.13
|
84
172
|
signing_key:
|
85
173
|
specification_version: 4
|
86
174
|
summary: Renames any ActiveRecord model and generates database migrations
|