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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 37c12086b5a533015bc567a51dfd106e812c5122c6a0e850069b982de8a10bb5
4
- data.tar.gz: dac7e0bf71d02e336b6a2a8b2ccf3a5e14f923dd98b43612bb95ee6675697303
3
+ metadata.gz: 34000b998f97e0525a90ba9ee7691dc4b114460e4bbf6e0f25dd17e428408a4a
4
+ data.tar.gz: 2e546baaa6091446448894796e9ab8869532f9dd68c478e96bf3a9d749adb511
5
5
  SHA512:
6
- metadata.gz: 311b2fbc36020b68f4fb191bf9df2009aa8ca2a65e90bc8caf22d12259b1d228665bd89a32402eca08185e278bef5839aa1f3bda75455caa22a1fb79fb568fde
7
- data.tar.gz: a0d48a9a39544df82adfca229d8af5204baea7707cd04a73874d1ec6943e9725df304de70ba1104ce8ec00876a13a81df7fa3ec509b5db3d1f5cf7bd771d0255
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 to display a Delete file on save checkbox
9
- # to submit a _purge array of attachments to purge.
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
- # As submitted by the form and permitted by our associations and options
62
+ # Returns the ActiveStorage::Attachment records selected for purging, matched by signed_id.
67
63
  def has_many_purgable_attachments
68
- submitted = (Array(_purge) - [nil, '', '0', ' ', 'false', 'f', 'off']).map(&:to_sym)
69
- submitted & has_many_purgable_names
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 |name|
74
- Array(public_send(name)).each { |attachment| attachment.mark_for_destruction unless attachment.new_record? }
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 |name|
82
- Rails.logger.info "[has_many_purgable] Purging #{name} attachments"
83
- Array(public_send(name)).each { |attachment| attachment.purge if attachment.marked_for_destruction? }
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
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '2.36.6'.freeze
2
+ VERSION = '2.37.0'.freeze
3
3
  end
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.36.6
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-03-27 00:00:00.000000000 Z
11
+ date: 2026-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails