soft_deleter 0.6.0 → 0.6.2

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: 754de2704b3c4dc4ccd80ecf91b3cf54a984de4a638a9147bcd942546f693a28
4
- data.tar.gz: b69dbb4e65731e1651a5b72b47b057fc9a8932d6dcf19193f2a34827cca4919d
3
+ metadata.gz: 51d9919bd61a3fdd0bf41ba052ba53f2b5a3e4efb8311df7894bd5d2f8ce470a
4
+ data.tar.gz: 125779c3092f28dfc97c9fe6f456b857f1f808b17fc784f62e77a3cf13f345fd
5
5
  SHA512:
6
- metadata.gz: 3c88417b44f595acf49d76e60bad3be44909f3ee83e4d2ba2f96ad4ee0ae9c51cf7a8a1f68b7e2ce87172b52df9ee0d6d28bd6b086e619c792b4c900dc255c93
7
- data.tar.gz: e8cacfd7614bfe063726a25493de187863e88ef17fc9ff8f36a88b84b778fc345fc206504ba752ae582fddd95c0f0dcd2ac5cd08c72135a745ebad85c48d402d
6
+ metadata.gz: 9f522fcba70a80bad8b40c48ab2705204518529053a72b6fd3bdbace9a5c15c00d7bdc2739b9e478e7d5a77ca5ad4b66b9b9baaa37c9daa67253990328165c80
7
+ data.tar.gz: dbd75a768e52861f15def16d6edc6043e993bb9f4b877899ae4da7e2e940982abff6701c665d35799d3699ea39738bccf36fee34ce0baab471e462585701b3b0
data/README.md CHANGED
@@ -29,7 +29,7 @@ Add some attributes to migration file, like name, email, age, ...etc.<br />
29
29
  And excute `bundle exec rails db:migrate`. That's all.<br />
30
30
  <br />
31
31
  Or if you already have User model, and you want introduce soft delete in it,
32
- create migration file and add lines like bellow
32
+ create migration file and add lines like below
33
33
  ```ruby
34
34
  class AddSoftDeleterAttributesToUsers < ActiveRecord::Migration[7.0]
35
35
  def change
@@ -52,12 +52,12 @@ end
52
52
  This line is added automatically if you use `rails g soft_deleter user` command to make user model.
53
53
 
54
54
  ### scope
55
- When you load users whitout soft deleted records, you need to scope like bellow.
55
+ When you load users whitout soft deleted records, you need to scope like below.
56
56
  ```ruby
57
57
  users = User.enabled.all
58
58
  ```
59
59
  If you don't use enabled scope, you will load users in all records including soft deleted.<br />
60
- Otherwise, if you need to load records with soft deleted, excute like bellow.
60
+ Otherwise, if you need to load records with soft deleted, excute like below.
61
61
  ```ruby
62
62
  deleted_users = User.deleted.all
63
63
  ```
@@ -114,8 +114,48 @@ And excute `user.restore`, then associations books, and sections are restored.<b
114
114
  It works with dependent destroy descriptions. If not, it doesn't work.
115
115
 
116
116
 
117
- ## Contributing
118
- Contribution directions go here.
117
+ ## Exclude Dependent
118
+ In the case where Active Storage is used, you will want exclude destroying files.<br />
119
+ You can exclude dependents by `exclude_dependent` as below.
120
+ ```ruby
121
+ # has_one_attached
122
+ class User < ApplicationRecord
123
+ include SoftDeleter
124
+
125
+ has_one_attached :avatar
126
+ exclude_dependent :avatar_attachment # this line
127
+ end
128
+
129
+ # has_many_attached
130
+ class Book < ApplicationRecord
131
+ include SoftDeleter
132
+ belongs_to :user
133
+ has_many_attached :images
134
+
135
+ exclude_dependent :images_attachments # this line
136
+ end
137
+ ```
138
+ `exclude_dependent` accepts array of symbols as arguments.<br />
139
+ You need to add suffix `_attachment` or `_attachments` depending on where you use has_one_attached or has_many_attached.
140
+
141
+ Otherwise, you can use `suffix` option as below.
142
+ ```ruby
143
+ class User < ApplicationRecord
144
+ include SoftDeleter
145
+
146
+ has_one_attached :avatar
147
+ has_one_attached :somefile
148
+ exclude_dependent %i(avatar somefile), suffix: :attachment # this line
149
+ end
150
+
151
+ class Book < ApplicationRecord
152
+ include SoftDeleter
153
+ belongs_to :user
154
+ has_many_attached :images
155
+
156
+ exclude_dependent :images, suffix: :attachments # this line
157
+ end
158
+ ```
119
159
 
120
160
  ## License
121
161
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,3 +1,3 @@
1
1
  module SoftDeleter
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.2"
3
3
  end
data/lib/soft_deleter.rb CHANGED
@@ -23,7 +23,7 @@ module SoftDeleter
23
23
 
24
24
  def exclude_dependent(names, option = {})
25
25
  dependents = [names].flatten
26
- dependents = dependents.map { |name| :"#{name}_#{option.dig(:sufix)}" } if option.dig(:sufix).present?
26
+ dependents = dependents.map { |name| :"#{name}_#{option.dig(:suffix)}" } if option.dig(:suffix).present?
27
27
 
28
28
  @@exclude_dependents += dependents
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soft_deleter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - testCodeV01
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-02-14 00:00:00.000000000 Z
11
+ date: 2025-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -17,7 +17,7 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 7.0.7
20
- type: :runtime
20
+ type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements: