effective_developer 0.8.3 → 0.8.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39fe3d6e71379807005ff5d46cf33e48e737b77d87e955bddaf6e6553453594a
4
- data.tar.gz: 11dac114ce2e61603fc215c05ae40ecd232ed9d3d12e1d69c5f7764e60cdb336
3
+ metadata.gz: 19ed54abb37c597e55d1b45aef357c4174881f79243d25edaf7ab0d540c121a1
4
+ data.tar.gz: 1179ac079bd24741a518040211600f84f68965e48f230920e1d5812d2ba6d98e
5
5
  SHA512:
6
- metadata.gz: 47dc5389da4b549cd036456bdde5a08e9312077df43fbc7903c2e3c9dd916b9d013c4bd2434b317e82098a08e72aa5fca569d52adab7e0ff3ada2b4ed5e3949b
7
- data.tar.gz: 3cd87bac6fb08a62e32e798e9e2ed1db0e6f8bf727033b2c1103529f15c1bd7962826185363e65dc68c969969d21093b0a44fc31b989f7110e1daf10815e1aac
6
+ metadata.gz: 31ffc32f164d5c76772dce297f257a8e11b397b565b4cf201b9df3d642d107e1f61352f73b8724954ee7834639529bcbc3f28c549f155bfac196073800564e40
7
+ data.tar.gz: ff8a97d65972d97b2ad5418217c827511e5342915d2b4df6ef73cb1c7a2f49503c51dda34d397d8f56124089d52b1dff5b055036c95f78a31312d81f3eafd438
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,58 @@
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
+ total = 0
21
+
22
+ places.each do |table, columns|
23
+ columns.each do |column|
24
+ sql = "SELECT COUNT(*) FROM #{table} WHERE #{column} ILIKE '%#{old_value}%'"
25
+ existing = ActiveRecord::Base.connection.execute(sql).first['count'].to_i
26
+ total += existing
27
+
28
+ puts "Replacing #{existing} occurrences of #{old_value} with #{new_value} in #{table}.#{column}"
29
+
30
+ sql = "UPDATE #{table} SET #{column} = REPLACE(#{column}, '#{old_value}', '#{new_value}') WHERE #{column} ILIKE '%#{old_value}%'"
31
+ ActiveRecord::Base.connection.execute(sql)
32
+ end
33
+ end
34
+
35
+ total
36
+ end
37
+
38
+ def count(old_value)
39
+ raise("old_value cannot contain a \' character") if old_value.include?("'")
40
+
41
+ total = 0
42
+
43
+ places.each do |table, columns|
44
+ columns.each do |column|
45
+ sql = "SELECT COUNT(*) FROM #{table} WHERE #{column} ILIKE '%#{old_value}%'"
46
+ existing = ActiveRecord::Base.connection.execute(sql).first['count'].to_i
47
+ total += existing
48
+
49
+ puts "There are #{existing} occurrences of #{old_value} in #{table}.#{column}"
50
+ end
51
+ end
52
+
53
+ total
54
+ end
55
+ alias_method :find, :count
56
+
57
+ end
58
+ end
@@ -1,3 +1,3 @@
1
1
  module EffectiveDeveloper
2
- VERSION = '0.8.3'.freeze
2
+ VERSION = '0.8.5'.freeze
3
3
  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.8.3
4
+ version: 0.8.5
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-09-10 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