effective_developer 0.2.5 → 0.2.6

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: cb87b48c7333c45473a85cf18fcc9e131e9b72b1
4
- data.tar.gz: 90c2899c904190613ae1910ad569b381b05a1529
3
+ metadata.gz: 22b439e6da5070f38393dcbc0f876b8c3d74899b
4
+ data.tar.gz: 894e2abe799d458168fc1ae9f6a11e34912b2b20
5
5
  SHA512:
6
- metadata.gz: 0f896654a9311c5cedb83cb921061a615d754ff739bf6a07527bd512d5979c87b1cf8ce9e0df3243759ddc9527b9c6e24ca080e491a84d1762ce8c714bc39cba
7
- data.tar.gz: 5b9132b98cbb27b1a6439ba0dbb2036190b0833e616dc865e345fb919031577d080d0978b022cfb02859f24df4b8e44b2c727ab56b2e221b94b74f8efde6c292
6
+ metadata.gz: 2c521f4a6caa21afbdc021a518b67771483ea3306dae2f222fcf56d9132f1596941462f0227f69285a212d9add5737e0bbfa4d344afb0fe906e9048d3b59a5bb
7
+ data.tar.gz: 59e2a645d664051e457e7a99321bf2482cbda6b96489da30bc1284f6432afe1f48eea1705906670327298328ecb2d3e4f8c52d1135d1dcd844c226c02dd3fd7d
data/README.md CHANGED
@@ -112,6 +112,27 @@ or
112
112
  rake csv:import:scaffold[users]
113
113
  ```
114
114
 
115
+ ## rename_class
116
+
117
+ Quickly rename a rails class throughout the entire app.
118
+
119
+ The script considers the `.classify`, `.pluralize` and `.singularize` common usage patterns.
120
+
121
+ Then performs a global search and replace, and renames files and directories.
122
+
123
+ ```ruby
124
+ rake rename_class[account,team]
125
+ ```
126
+
127
+ or
128
+
129
+ ```ruby
130
+ rake rename_class[account,team,skipdb]
131
+ ```
132
+
133
+ to skip any changes to database migrations.
134
+
135
+
115
136
  ## reset_pk_sequence
116
137
 
117
138
  If you ever run into the error `duplicate key violates unique constraint (id) error`, run this script:
@@ -12,12 +12,13 @@ module Effective
12
12
  @from = []
13
13
  @to = []
14
14
 
15
- @lines = File.open(filename).readlines
15
+ @changed = false
16
16
 
17
- block.call(self)
17
+ @lines = File.open(filename).readlines
18
18
 
19
- File.open(filename, 'w') do |file|
20
- lines.each { |line| file.write(line) }
19
+ if block_given?
20
+ block.call(self)
21
+ write!
21
22
  end
22
23
  end
23
24
 
@@ -90,7 +91,7 @@ module Effective
90
91
  end
91
92
  end
92
93
 
93
- true
94
+ @changed = true
94
95
  end
95
96
 
96
97
  def insert_raw(content, index, depth = 0)
@@ -107,6 +108,8 @@ module Effective
107
108
 
108
109
  index += 1
109
110
  end
111
+
112
+ @changed = true
110
113
  end
111
114
 
112
115
  # Iterate over the lines with a depth, and passed the stripped line to the passed block
@@ -194,8 +197,26 @@ module Effective
194
197
  depth
195
198
  end
196
199
 
200
+ def changed?
201
+ @changed == true
202
+ end
203
+
204
+ def gsub!(source, target)
205
+ lines.each { |line| @changed = true if line.gsub!(source, target) }
206
+ end
207
+
197
208
  private
198
209
 
210
+ def write!
211
+ return false unless changed?
212
+
213
+ File.open(filename, 'w') do |file|
214
+ lines.each { |line| file.write(line) }
215
+ end
216
+
217
+ true
218
+ end
219
+
199
220
  def open?(content)
200
221
  stripped = ss(content)
201
222
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveDeveloper
2
- VERSION = '0.2.5'.freeze
2
+ VERSION = '0.2.6'.freeze
3
3
  end
@@ -7,8 +7,6 @@
7
7
  <% end -%>
8
8
  <% if defined?(EffectiveDatatables) -%>
9
9
  - if @datatable.present?
10
- = render_datatable_charts(@datatable)
11
- = render_datatable_filters(@datatable)
12
10
  = render_datatable(@datatable)
13
11
  - else
14
12
  %p There are no <%= resource.plural_name %>.
@@ -0,0 +1,59 @@
1
+ # bundle exec rake rename_class[account, team]
2
+
3
+ desc 'Rename a rails class to another'
4
+ task :rename_class, [:source, :target, :db] => :environment do |t, args|
5
+ unless args.source.present? && args.target.present?
6
+ puts 'usage: rake rename_class[account,team] (or rake rename_class[account,team,skipdb] to skip database migrations)' and exit
7
+ end
8
+
9
+ source = args.source.to_s.downcase.singularize
10
+ target = args.target.to_s.downcase.singularize
11
+
12
+ puts "=== Renaming class '#{source.classify}' to '#{target.classify}'"
13
+
14
+ whitelist = ['app/', 'db/', 'lib/', 'test/'].compact
15
+ blacklist = ['db/schema.rb', ('db/migrate' if args.db == 'skipdb')].compact
16
+
17
+ # Rename any directories in the app
18
+ Dir.glob('**/*').each do |path|
19
+ next unless whitelist.any? { |ok| path.start_with?(ok) }
20
+ next if blacklist.any? { |nope| path.start_with?(nope) }
21
+ next unless File.directory?(path)
22
+
23
+ changed = path.gsub(source.pluralize, target.pluralize).gsub(source, target)
24
+
25
+ if path != changed
26
+ File.rename(path, changed)
27
+ puts "renamed: #{path} => #{changed}"
28
+ end
29
+ end
30
+
31
+ # For every file in the app
32
+ Dir.glob('**/*.*').each do |path|
33
+ next unless whitelist.any? { |ok| path.start_with?(ok) }
34
+ next if blacklist.any? { |nope| path.start_with?(nope) }
35
+
36
+ changed = path.gsub(source.pluralize, target.pluralize).gsub(source, target)
37
+
38
+ if path != changed
39
+ File.rename(path, changed)
40
+ puts "renamed: #{path} => #{changed}"
41
+ end
42
+ end
43
+
44
+ # For every file in the app
45
+ Dir.glob('**/*.*').each do |path|
46
+ next unless whitelist.any? { |ok| path.start_with?(ok) }
47
+ next if blacklist.any? { |nope| path.start_with?(nope) }
48
+
49
+ writer = Effective::CodeWriter.new(path) do |w|
50
+ w.gsub!(source.classify.pluralize, target.classify.pluralize)
51
+ w.gsub!(source.classify, target.classify)
52
+ w.gsub!(source.pluralize, target.pluralize)
53
+ w.gsub!(source, target)
54
+ end
55
+
56
+ puts "updated: #{path}" if writer.changed?
57
+ end
58
+
59
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_developer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-25 00:00:00.000000000 Z
11
+ date: 2017-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -94,6 +94,7 @@ files:
94
94
  - lib/scaffolds/views/show.html.haml
95
95
  - lib/tasks/effective_csv_importer.rake
96
96
  - lib/tasks/pg_pull.rake
97
+ - lib/tasks/rename_class.rake
97
98
  - lib/tasks/reset_pk_sequence.rake
98
99
  - lib/tasks/validate.rake
99
100
  homepage: https://github.com/code-and-effect/effective_developer