effective_developer 0.8.2 → 0.8.4

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
  SHA256:
3
- metadata.gz: 0f683ab9dcda556c93330af2e81a50c584768c8f0464c1124a6d0af2a9eadf99
4
- data.tar.gz: 2935dd2fef5e23e7a8470e436f1c7e613c561b556737f6c741273276b1372c5a
3
+ metadata.gz: 8fba16ab5113f2da3b2868adf4bf3637728a1fa014ee77f3145e20662f7388dc
4
+ data.tar.gz: b178128f65a9ac17b175e4346289fba89c5bbead7d7102d6af33ac84f9cbf012
5
5
  SHA512:
6
- metadata.gz: 706e83a7ed877f3fd686ca4b251db6dc68d393c89401e7266b2f3bfea9cec0c7d8364deda7f1dc3ba393d9f7edec3ec59c2a4d44d2a53e44e443993b5d9e67e9
7
- data.tar.gz: 639e094e77930330bbd6bc2695b058bea2ddf2333b7b74cfc115be8afadd6f454626b13f77060d8dbb0f0b540ea71bce83953154588e5a7b58e4519045bb8be0
6
+ metadata.gz: c204417a800c42f41e313ee4c4af7301988224baf9ccce225f1a8bdb12cf519bd6c52003a5636c9461a8045f5e27f1ad4f3f6a1b21278913d60109d6a86d2b80
7
+ data.tar.gz: e7238d4b8592aab380b80dfcb9fc82c2a45e9be0534c9cfc5f13258135df6d9c7fb5ce6e60edcf4329d8682c6ec0d99711fb381cefee9e3fed0e3f68cfd63c1b
data/README.md CHANGED
@@ -449,6 +449,20 @@ You can do this:
449
449
  Region.update_all("snippets = REPLACE(snippets, 'ActionController::Parameters', 'ActiveSupport::HashWithIndifferentAccess')")
450
450
  ```
451
451
 
452
+ ## Content Replacer
453
+
454
+ To find & replace content in the action_text_rich_texts body column:
455
+
456
+ ```
457
+ Effective::ContentReplacer.new.count("foo")
458
+ ```
459
+
460
+ and
461
+
462
+ ```
463
+ Effective::ContentReplacer.new.replace!("foo", "bar")
464
+ ```
465
+
452
466
  ## License
453
467
 
454
468
  MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+ # Effective::ContentReplacer.new.replace!("foo", "bar")
3
+
4
+ module Effective
5
+ class ContentReplacer
6
+ attr_accessor :places
7
+
8
+ def initialize(places = nil)
9
+ @places = (places || default_places)
10
+ end
11
+
12
+ def default_places
13
+ { action_text_rich_texts: [:body] }
14
+ end
15
+
16
+ def replace!(old_value, new_value)
17
+ raise("old_value cannot contain a \' character") if old_value.include?("'")
18
+ raise("new_value cannot contain a \' character") if new_value.include?("'")
19
+
20
+ places.each do |table, columns|
21
+ columns.each do |column|
22
+ sql = "SELECT COUNT(*) FROM #{table} WHERE #{column} ILIKE '%#{old_value}%'"
23
+ existing = ActiveRecord::Base.connection.execute(sql).first['count'].to_i
24
+
25
+ puts "Replacing #{existing} occurrences of #{old_value} with #{new_value} in #{table}.#{column}"
26
+
27
+ sql = "UPDATE #{table} SET #{column} = REPLACE(#{column}, '#{old_value}', '#{new_value}') WHERE #{column} ILIKE '%#{old_value}%'"
28
+ ActiveRecord::Base.connection.execute(sql)
29
+ end
30
+ end
31
+
32
+ true
33
+ end
34
+
35
+ def count(old_value)
36
+ raise("old_value cannot contain a \' character") if old_value.include?("'")
37
+
38
+ places.each do |table, columns|
39
+ columns.each do |column|
40
+ sql = "SELECT COUNT(*) FROM #{table} WHERE #{column} ILIKE '%#{old_value}%'"
41
+ existing = ActiveRecord::Base.connection.execute(sql).first['count'].to_i
42
+
43
+ puts "There are #{existing} occurrences of #{old_value} in #{table}.#{column}"
44
+ end
45
+ end
46
+ end
47
+
48
+ end
49
+ end
@@ -1,3 +1,3 @@
1
1
  module EffectiveDeveloper
2
- VERSION = '0.8.2'.freeze
2
+ VERSION = '0.8.4'.freeze
3
3
  end
@@ -53,9 +53,11 @@ module Effective
53
53
  abilities += non_crud_actions
54
54
  end
55
55
 
56
- abilities = ['manage'] if abilities.blank? || abilities == (crud_actions - ['show'])
56
+ abilities = ['crud'] if abilities.blank? || abilities == (crud_actions - ['show'])
57
57
 
58
- if abilities.length == 1
58
+ if abilities == ['crud']
59
+ abilities = "#{abilities.first}"
60
+ elsif abilities.length == 1
59
61
  abilities = ":#{abilities.first}"
60
62
  else
61
63
  abilities = '[' + abilities.map { |action| ':' + action }.join(', ') + ']'
@@ -67,7 +69,7 @@ module Effective
67
69
  resource.class_name
68
70
  end
69
71
 
70
- "can #{abilities}, #{name}"
72
+ "can(#{abilities}, #{name})"
71
73
  )
72
74
  end
73
75
  end
@@ -1,5 +1,5 @@
1
1
  = tabs do
2
- = tab '<%= resource.human_name.titleize %>' do
2
+ = tab(<%= resource.name %>) do
3
3
  = render '<%= resource.view_file_path("form_#{resource.name}").sub('effective/', '') %>', <%= resource.name %>: <%= resource.name %>
4
4
 
5
5
  <%- if resource.nested_resources.present? || resource.instance.respond_to?(:logs_datatable) %>
@@ -1,5 +1,5 @@
1
1
  = tabs do
2
- = tab '<%= resource.human_name.titleize %>' do
2
+ = tab(<%= resource.name %>) do
3
3
  = render '<%= resource.view_file_path("form_#{resource.name}") %>', <%= resource.name %>: <%= resource.name %>
4
4
 
5
5
  <%- if resource.nested_resources.present? %>
@@ -1,5 +1,5 @@
1
1
  = tabs do
2
- = tab '<%= resource.human_name.titleize %>' do
2
+ = tab(<%= resource.name %>) do
3
3
  = render '<%= resource.view_file_path("form_#{resource.name}") %>', <%= resource.name %>: <%= resource.name %>
4
4
 
5
5
  <%- if resource.nested_resources.present? || resource.instance.respond_to?(:logs_datatable) %>
@@ -14,10 +14,10 @@ namespace :pg do
14
14
  # DATABASE=example bundle exec rake pg:load
15
15
  desc 'Creates a new backup on remote server and downloads it to latest.dump'
16
16
  task :pull, [:remote] => :environment do |t, args|
17
- defaults = { database: nil, filename: (ENV['DATABASE'] || 'latest') + '.dump', logs: 'false' }
18
- env_keys = { database: ENV['DATABASE'], filename: ENV['FILENAME'], logs: ENV['LOGS'].to_s.presence }
17
+ defaults = { database: nil, filename: (ENV['DATABASE'] || 'latest') + '.dump', logs: 'false' }.compact
18
+ env_keys = { database: ENV['DATABASE'], filename: ENV['FILENAME'], logs: ENV['LOGS'] }.compact
19
19
  keywords = ARGV.map { |a| a.split('=') if a.include?('=') }.compact.inject({}) { |h, (k, v)| h[k.to_sym] = v; h }
20
- args.with_defaults(defaults.compact.merge(env_keys.compact).merge(keywords))
20
+ args.with_defaults(defaults.merge(env_keys).merge(keywords))
21
21
 
22
22
  # Validate Config
23
23
  configs = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env)
@@ -42,7 +42,7 @@ namespace :pg do
42
42
  end
43
43
 
44
44
  # Download it to local
45
- unless system("curl -o #{args.filename} `heroku pg:backups:public-url --remote #{args.remote}`")
45
+ unless system("curl -o #{args.filename} `heroku pg:backups:url --remote #{args.remote}`")
46
46
  abort("Error downloading database")
47
47
  end
48
48
 
@@ -93,10 +93,10 @@ namespace :pg do
93
93
  # DATABASE=example bundle exec rake pg:load
94
94
  desc 'Loads a postgresql .dump file into the development database (latest.dump by default)'
95
95
  task :load, [:filename] => :environment do |t, args|
96
- defaults = { database: nil, filename: (ENV['DATABASE'] || 'latest') + '.dump' }
97
- env_keys = { database: ENV['DATABASE'], filename: ENV['FILENAME'] }
96
+ defaults = { database: nil, filename: (ENV['DATABASE'] || 'latest') + '.dump' }.compact
97
+ env_keys = { database: ENV['DATABASE'], filename: ENV['FILENAME'] }.compact
98
98
  keywords = ARGV.map { |a| a.split('=') if a.include?('=') }.compact.inject({}) { |h, (k, v)| h[k.to_sym] = v; h }
99
- args.with_defaults(defaults.compact.merge(env_keys.compact).merge(keywords))
99
+ args.with_defaults(defaults.merge(env_keys).merge(keywords))
100
100
 
101
101
  # Validate filename
102
102
  unless File.exist?(Rails.root + args.filename)
@@ -143,10 +143,10 @@ namespace :pg do
143
143
  # bundle exec rake pg:save[something.dump] => Will dump the database to something.dump
144
144
  desc 'Saves the development database to a postgresql .dump file (latest.dump by default)'
145
145
  task :save, [:filename] => :environment do |t, args|
146
- defaults = { database: nil, filename: (ENV['DATABASE'] || 'latest') + '.dump', logs: 'false' }
147
- env_keys = { database: ENV['DATABASE'], filename: ENV['FILENAME'], logs: ENV['LOGS'].to_s.presence }
146
+ defaults = { database: nil, filename: (ENV['DATABASE'] || 'latest') + '.dump', logs: 'false' }.compact
147
+ env_keys = { database: ENV['DATABASE'], filename: ENV['FILENAME'], logs: ENV['LOGS'] }.compact
148
148
  keywords = ARGV.map { |a| a.split('=') if a.include?('=') }.compact.inject({}) { |h, (k, v)| h[k.to_sym] = v; h }
149
- args.with_defaults(defaults.compact.merge(env_keys.compact).merge(keywords))
149
+ args.with_defaults(defaults.merge(env_keys).merge(keywords))
150
150
 
151
151
  db = if ENV['DATABASE_URL'].to_s.length > 0 && args.database.blank?
152
152
  uri = URI.parse(ENV['DATABASE_URL']) rescue nil
@@ -210,10 +210,10 @@ namespace :pg do
210
210
  abort "Error capturing heroku backup"
211
211
  end
212
212
 
213
- url = (`heroku pg:backups:public-url --app #{args.source}`).chomp
213
+ url = (`heroku pg:backups:url --app #{args.source}`).chomp
214
214
 
215
215
  unless (url || '').length > 0
216
- abort "Error reading public-url from app #{args.source}"
216
+ abort "Error reading url from app #{args.source}"
217
217
  end
218
218
 
219
219
  unless system("heroku pg:backups:restore '#{url}' DATABASE_URL --app #{args.target}")
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.8.2
4
+ version: 0.8.4
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: 2024-04-19 00:00:00.000000000 Z
11
+ date: 2024-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -50,6 +50,7 @@ files:
50
50
  - Rakefile
51
51
  - app/models/effective/annotator.rb
52
52
  - app/models/effective/code_writer.rb
53
+ - app/models/effective/content_replacer.rb
53
54
  - app/models/effective/csv_importer.rb
54
55
  - app/models/effective/form_upgrader.rb
55
56
  - app/models/effective/live_generator.rb