soft_deleter 0.1.1 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 128f9591b3e2fa2005aa7bb7722c83291a341af111d2f208bdba0bd5bcd050dd
4
- data.tar.gz: 6e2cd7dea9ebfdee761cbad7a615920da78a378394ed51c9a8f67b48571af08b
3
+ metadata.gz: 3bf0adcc2f508e278c3297a8bb985e92713c1b834a2f456c97115eebb0fe564a
4
+ data.tar.gz: ff5ede62ab6f8259d0ac1cd23fdb7e6238b340944041b177b9f6557bd2bdd64c
5
5
  SHA512:
6
- metadata.gz: a99e22f07eda44d726c803aa9f0a2c95f831a1f2af52788663c32b4eb577eadda9fec044a822f03c161e8533fee514e6de18faa9de7b411d9f866d92bce4c757
7
- data.tar.gz: f4b7c19000066067279b95a79e85895a78a1db457f769a5801e6adb3f5c4b213f5a479d791ab17c91dc6ab548c50b2c5341cfd14fbff6883caaf901d428e8159
6
+ metadata.gz: 52b7566201dd79a969e4810a89041fda50d8c963c7e4d1208c7568c05adf9f8be21247cf8e331bccf0f45eb9946c8262b76744e8e652d7d18992240834272f48
7
+ data.tar.gz: d95528228aeb88ae76e460ad26cd111f5e401bcfa361ae03995f1c3654d6d389dd8bec4e227e2b0173f76e18408369ad942ed009303b34c4b99be4fb371ad556
@@ -1,3 +1,3 @@
1
1
  module SoftDeleter
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/soft_deleter.rb CHANGED
@@ -33,6 +33,16 @@ module SoftDeleter
33
33
  with_associations(:soft_delete_witout_associations, deleter)
34
34
  end
35
35
 
36
+ true
37
+ rescue ActiveRecord::RecordInvalid
38
+ false
39
+ end
40
+
41
+ def restore!
42
+ ActiveRecord::Base.transaction do
43
+ with_associations(:restore_without_associations!)
44
+ end
45
+
36
46
  true
37
47
  end
38
48
 
@@ -40,6 +50,10 @@ module SoftDeleter
40
50
  ActiveRecord::Base.transaction do
41
51
  with_associations(:restore_without_associations)
42
52
  end
53
+
54
+ true
55
+ rescue ActiveRecord::RecordInvalid
56
+ false
43
57
  end
44
58
 
45
59
  def deleter_type
@@ -75,6 +89,8 @@ module SoftDeleter
75
89
  private
76
90
 
77
91
  def soft_delete_witout_associations!(deleter)
92
+ raise ActiveRecord::RecordInvalid, self if invalid?
93
+
78
94
  update!(
79
95
  deleter_type: deleter.class.to_s,
80
96
  deleter_id: deleter.id,
@@ -83,6 +99,8 @@ module SoftDeleter
83
99
  end
84
100
 
85
101
  def soft_delete_witout_associations(deleter)
102
+ raise ActiveRecord::RecordInvalid if invalid?
103
+
86
104
  update(
87
105
  deleter_type: deleter.class.to_s,
88
106
  deleter_id: deleter.id,
@@ -90,7 +108,19 @@ module SoftDeleter
90
108
  )
91
109
  end
92
110
 
111
+ def restore_without_associations!
112
+ raise ActiveRecord::RecordInvalid, self if invalid?
113
+
114
+ update(
115
+ deleter_type: nil,
116
+ deleter_id: nil,
117
+ deleted_at: nil
118
+ )
119
+ end
120
+
93
121
  def restore_without_associations
122
+ raise ActiveRecord::RecordInvalid if invalid?
123
+
94
124
  update(
95
125
  deleter_type: nil,
96
126
  deleter_id: nil,
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.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - testCodeV01
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-25 00:00:00.000000000 Z
11
+ date: 2023-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails