effective_developer 0.8.3 → 0.8.4

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: 8fba16ab5113f2da3b2868adf4bf3637728a1fa014ee77f3145e20662f7388dc
4
+ data.tar.gz: b178128f65a9ac17b175e4346289fba89c5bbead7d7102d6af33ac84f9cbf012
5
5
  SHA512:
6
- metadata.gz: 47dc5389da4b549cd036456bdde5a08e9312077df43fbc7903c2e3c9dd916b9d013c4bd2434b317e82098a08e72aa5fca569d52adab7e0ff3ada2b4ed5e3949b
7
- data.tar.gz: 3cd87bac6fb08a62e32e798e9e2ed1db0e6f8bf727033b2c1103529f15c1bd7962826185363e65dc68c969969d21093b0a44fc31b989f7110e1daf10815e1aac
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.3'.freeze
2
+ VERSION = '0.8.4'.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.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-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