effective_developer 0.8.3 → 0.8.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -0
- data/app/models/effective/content_replacer.rb +49 -0
- data/lib/effective_developer/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fba16ab5113f2da3b2868adf4bf3637728a1fa014ee77f3145e20662f7388dc
|
4
|
+
data.tar.gz: b178128f65a9ac17b175e4346289fba89c5bbead7d7102d6af33ac84f9cbf012
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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.
|
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-
|
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
|