soft_deleter 0.6.0 → 0.6.1
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 +45 -3
- data/lib/soft_deleter/version.rb +1 -1
- data/lib/soft_deleter.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02c66d881295059cfb19ec7d833998bfbedc484df9896749fa74fe4187e63a60
|
4
|
+
data.tar.gz: e3ab5dc4fcb07a1aa23dd1e3a1616792ccefeb7d02a15fcb08861f3d4e6a34e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd0a840fec5163ea10e321213c765b2c4b60b8bf39d12642f655605114ced698d2c58f41fbeddaee4b1d7f201ab4abfcedeaedc1e77e103e26154d165087d7aa
|
7
|
+
data.tar.gz: 5f5b88167282c363afe6d5e927128913c56037f3ea48752794e43ec0966a53b609e35c6acd31b9b9895d15bb15d1eb0919563f5b7efca0cf883b30abedc05217
|
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
|
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
|
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
|
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,6 +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
|
+
## 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
|
136
|
+
end
|
137
|
+
```
|
138
|
+
`exclude_dependent` accepts array of symbols as arguments.
|
139
|
+
|
140
|
+
Otherwise, you can use `suffix` option as below.
|
141
|
+
```ruby
|
142
|
+
class User < ApplicationRecord
|
143
|
+
include SoftDeleter
|
144
|
+
|
145
|
+
has_one_attached :avatar
|
146
|
+
has_one_attached :somefile
|
147
|
+
exclude_dependent %i(avatar somefile), suffix: :attachment # this line
|
148
|
+
end
|
149
|
+
|
150
|
+
class Book < ApplicationRecord
|
151
|
+
include SoftDeleter
|
152
|
+
belongs_to :user
|
153
|
+
has_many_attached :images
|
154
|
+
|
155
|
+
exclude_dependent :images, suffix: :attachments
|
156
|
+
end
|
157
|
+
```
|
158
|
+
|
117
159
|
## Contributing
|
118
160
|
Contribution directions go here.
|
119
161
|
|
data/lib/soft_deleter/version.rb
CHANGED
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(:
|
26
|
+
dependents = dependents.map { |name| :"#{name}_#{option.dig(:suffix)}" } if option.dig(:suffix).present?
|
27
27
|
|
28
28
|
@@exclude_dependents += dependents
|
29
29
|
end
|