effective_resources 2.36.6 → 2.37.0
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/app/models/concerns/has_many_purgable.rb +14 -15
- data/lib/effective_resources/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 34000b998f97e0525a90ba9ee7691dc4b114460e4bbf6e0f25dd17e428408a4a
|
|
4
|
+
data.tar.gz: 2e546baaa6091446448894796e9ab8869532f9dd68c478e96bf3a9d749adb511
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4ecc3665cc1e92b791074c01921ef422310ed10706b6f0948f9b13e4a4a3be537e562e6e0e043e55736738a6afe94e78f9fb9d9a0ae96173827c8c707a5d479b
|
|
7
|
+
data.tar.gz: f53e5948e27a4b43155a3ec53de5085389d917932f020acb929142b13cefa050baccc54e8beeee58161f72ef371609cdc7707884c868ac287618118165011635
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
#
|
|
6
6
|
# Pass 'has_many_purgable :files, :avatar' to only allow the files and avatar to be purged.
|
|
7
7
|
#
|
|
8
|
-
# Works with effective_bootstrap file_field
|
|
9
|
-
#
|
|
8
|
+
# Works with effective_bootstrap file_field, which renders a Remove button per attachment
|
|
9
|
+
# that submits the attachment's signed_id in the _purge array.
|
|
10
10
|
#
|
|
11
11
|
# You must permit the attribute _purge: []
|
|
12
12
|
|
|
@@ -53,34 +53,33 @@ module HasManyPurgable
|
|
|
53
53
|
# All the possible names, merging the actual associations and the given options
|
|
54
54
|
def has_many_purgable_names
|
|
55
55
|
names = has_many_purgable_options.fetch(:names)
|
|
56
|
-
|
|
57
|
-
associations = self.class.reflect_on_all_associations
|
|
58
|
-
.select { |ass| ass.class_name == 'ActiveStorage::Attachment' }
|
|
59
|
-
.map { |ass| ass.name.to_s.chomp('_attachments').chomp('_attachment').to_sym }
|
|
60
|
-
|
|
56
|
+
associations = self.class.attachment_reflections.keys.map(&:to_sym)
|
|
61
57
|
names == :all ? associations : (names & associations)
|
|
62
58
|
end
|
|
63
59
|
|
|
64
60
|
private
|
|
65
61
|
|
|
66
|
-
#
|
|
62
|
+
# Returns the ActiveStorage::Attachment records selected for purging, matched by signed_id.
|
|
67
63
|
def has_many_purgable_attachments
|
|
68
|
-
submitted =
|
|
69
|
-
|
|
64
|
+
submitted = Array(_purge) - [nil, '', '0', ' ', 'false', 'f', 'off']
|
|
65
|
+
return [] if submitted.blank?
|
|
66
|
+
|
|
67
|
+
all_attachments = has_many_purgable_names.flat_map { |name| Array(public_send(name)) }
|
|
68
|
+
all_attachments.select { |attachment| submitted.include?(attachment.signed_id) }
|
|
70
69
|
end
|
|
71
70
|
|
|
72
71
|
def has_many_purgable_mark_for_destruction
|
|
73
|
-
has_many_purgable_attachments.each do |
|
|
74
|
-
|
|
72
|
+
has_many_purgable_attachments.each do |attachment|
|
|
73
|
+
attachment.mark_for_destruction unless attachment.new_record?
|
|
75
74
|
end
|
|
76
75
|
|
|
77
76
|
true
|
|
78
77
|
end
|
|
79
78
|
|
|
80
79
|
def has_many_purgable_purge
|
|
81
|
-
has_many_purgable_attachments.each do |
|
|
82
|
-
Rails.logger.info "[has_many_purgable] Purging #{name}
|
|
83
|
-
|
|
80
|
+
has_many_purgable_attachments.each do |attachment|
|
|
81
|
+
Rails.logger.info "[has_many_purgable] Purging attachment #{attachment.id} (#{attachment.name})"
|
|
82
|
+
attachment.purge if attachment.marked_for_destruction?
|
|
84
83
|
end
|
|
85
84
|
|
|
86
85
|
true
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: effective_resources
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.37.0
|
|
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: 2026-
|
|
11
|
+
date: 2026-04-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|