model_renamer 0.1.5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f3d54f2d439c6e9c3a514a11fcd1de27b4934887
4
- data.tar.gz: 99f9d126162c25f118396a7ac77b037efcd9dd4e
3
+ metadata.gz: f5e42b0a3bfd2fe82b23f951f1a15062ac0c8f29
4
+ data.tar.gz: c1f5b417f6a45de0a8eff12be12c6e49aa315c7f
5
5
  SHA512:
6
- metadata.gz: f9e26e21bb329aa68e093dca8239661866555986d40dc5bee146eaf7942e82002d97566a2fc2d1782524e6f17526a96fcbd910cfdcfffe30ea64ff656d292471
7
- data.tar.gz: 7d30a203890ff711779041b0c1f871269e3df4a4f8b22443f11e65c1cebff6f57c6a16b7101f89723a736f2655ee6b43b7a06ee18b84838a43134a8d13e2b2fb
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
@@ -0,0 +1 @@
1
+ model_renamer
@@ -0,0 +1 @@
1
+ 2.4.1
data/Gemfile CHANGED
@@ -1,5 +1,2 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'activerecord'
4
- gem 'activesupport'
5
- gem 'rails'
1
+ source "https://rubygems.org"
2
+ gemspec
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").rename_and_generate_migrations
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 in the codebase, run:
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").rename
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])[1]
14
+ path = Rails::Generators.invoke("active_record:migration", [migration_name])[0]
15
15
  File.write(path, migration_file_content)
16
16
  end
17
17
 
@@ -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
- def initialize old_name, new_name
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 rename_and_generate_migrations
12
- rename
21
+ def run
22
+ rename_files_and_directories @path
23
+ rename_in_files
13
24
  generate_migrations
14
25
  end
15
26
 
16
- def rename
17
- replace_all_occurrences
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 replace_all_occurrences
27
- all_filepaths.each do |filepath|
28
- replace_all_variations_in_file filepath
29
- rename_file filepath
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
- 'js', 'coffee', 'hamlc', 'skim', 'erb',
46
- 'sass', 'scss', 'css', 'rb', 'slim',
47
- 'haml', 'rabl', 'html', 'txt', 'feature',
48
- 'rake', 'json', 'sh', 'yaml'
49
- ].include? path.split('.').last
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
@@ -1,3 +1,3 @@
1
1
  module ModelRenamer
2
- VERSION = "0.1.5"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -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.1.5
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: 2015-10-05 00:00:00.000000000 Z
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.2.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