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 +4 -4
- data/README.md +14 -0
- data/app/models/effective/content_replacer.rb +58 -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: 19ed54abb37c597e55d1b45aef357c4174881f79243d25edaf7ab0d540c121a1
|
4
|
+
data.tar.gz: 1179ac079bd24741a518040211600f84f68965e48f230920e1d5812d2ba6d98e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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.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-
|
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
|