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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 754de2704b3c4dc4ccd80ecf91b3cf54a984de4a638a9147bcd942546f693a28
4
- data.tar.gz: b69dbb4e65731e1651a5b72b47b057fc9a8932d6dcf19193f2a34827cca4919d
3
+ metadata.gz: 02c66d881295059cfb19ec7d833998bfbedc484df9896749fa74fe4187e63a60
4
+ data.tar.gz: e3ab5dc4fcb07a1aa23dd1e3a1616792ccefeb7d02a15fcb08861f3d4e6a34e4
5
5
  SHA512:
6
- metadata.gz: 3c88417b44f595acf49d76e60bad3be44909f3ee83e4d2ba2f96ad4ee0ae9c51cf7a8a1f68b7e2ce87172b52df9ee0d6d28bd6b086e619c792b4c900dc255c93
7
- data.tar.gz: e8cacfd7614bfe063726a25493de187863e88ef17fc9ff8f36a88b84b778fc345fc206504ba752ae582fddd95c0f0dcd2ac5cd08c72135a745ebad85c48d402d
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 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,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
 
@@ -1,3 +1,3 @@
1
1
  module SoftDeleter
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
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,7 +1,7 @@
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - testCodeV01