mongoid_paranoia 0.4.1 → 0.5.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 +4 -4
- data/lib/mongoid/paranoia.rb +21 -31
- data/lib/mongoid/paranoia/version.rb +1 -1
- data/spec/mongoid/paranoia_spec.rb +6 -6
- metadata +3 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec456afdb66a1a23fdb5dc73db06b9dc6344932f8aa3c95b378ca60560aea474
|
4
|
+
data.tar.gz: b80b6cfaedfb9523b9dbfe791d586493eb4c9d3e65b7286d3cdc2010d8f9874e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3aff3ad8f7f06f0a1498143baf6cf72d58c24b99b3a4f0bfb19fd314ec836625356291989293ddee2dc230d148dda65f84bc153660bd00566ba8bc727e21ee9f
|
7
|
+
data.tar.gz: 5322c2f12d84591a8e0bc3463faf1e82571f09c5877bc3a3f7bcfbf7c10c87e198bb8be2add2ab42c6e71341df77fdbe7dbe368ccc476d7e44c8f41839c283cb
|
data/lib/mongoid/paranoia.rb
CHANGED
@@ -50,23 +50,6 @@ module Mongoid
|
|
50
50
|
define_model_callbacks :remove
|
51
51
|
end
|
52
52
|
|
53
|
-
# Delete the paranoid +Document+ from the database completely. This will
|
54
|
-
# run the destroy callbacks.
|
55
|
-
#
|
56
|
-
# @example Hard destroy the document.
|
57
|
-
# document.destroy!
|
58
|
-
#
|
59
|
-
# @return [ true, false ] If the operation succeeded.
|
60
|
-
#
|
61
|
-
# @since 1.0.0
|
62
|
-
def destroy!
|
63
|
-
run_callbacks(:destroy) do
|
64
|
-
run_callbacks(:remove) do
|
65
|
-
delete!
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
53
|
# Override the persisted method to allow for the paranoia gem.
|
71
54
|
# If a paranoid record is selected, then we only want to check
|
72
55
|
# if it's a new record, not if it is "destroyed"
|
@@ -92,34 +75,41 @@ module Mongoid
|
|
92
75
|
# @return [ true ] True.
|
93
76
|
#
|
94
77
|
# @since 1.0.0
|
95
|
-
alias
|
78
|
+
alias :orig_delete :delete
|
96
79
|
|
97
80
|
def remove(_ = {})
|
98
|
-
return false unless catch(:abort) do
|
99
|
-
if respond_to?(:apply_destroy_dependencies!)
|
100
|
-
apply_destroy_dependencies!
|
101
|
-
else
|
102
|
-
apply_delete_dependencies!
|
103
|
-
end
|
104
|
-
end
|
105
81
|
time = self.deleted_at = Time.now
|
106
82
|
_paranoia_update('$set' => { paranoid_field => time })
|
107
83
|
@destroyed = true
|
108
84
|
true
|
109
85
|
end
|
110
86
|
|
111
|
-
alias delete :remove
|
87
|
+
alias :delete :remove
|
88
|
+
alias :delete! :orig_delete
|
112
89
|
|
113
|
-
# Delete the paranoid +Document+ from the database completely.
|
90
|
+
# Delete the paranoid +Document+ from the database completely. This will
|
91
|
+
# run the destroy and remove callbacks.
|
114
92
|
#
|
115
|
-
# @example Hard
|
116
|
-
# document.
|
93
|
+
# @example Hard destroy the document.
|
94
|
+
# document.destroy!
|
117
95
|
#
|
118
96
|
# @return [ true, false ] If the operation succeeded.
|
119
97
|
#
|
120
98
|
# @since 1.0.0
|
121
|
-
def
|
122
|
-
|
99
|
+
def destroy!(options = {})
|
100
|
+
raise Errors::ReadonlyDocument.new(self.class) if readonly?
|
101
|
+
self.flagged_for_destroy = true
|
102
|
+
result = run_callbacks(:destroy) do
|
103
|
+
run_callbacks(:remove) do
|
104
|
+
if catch(:abort) { apply_destroy_dependencies! }
|
105
|
+
delete!(options || {})
|
106
|
+
else
|
107
|
+
false
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
self.flagged_for_destroy = false
|
112
|
+
result
|
123
113
|
end
|
124
114
|
|
125
115
|
# Determines if this document is destroyed.
|
@@ -531,10 +531,10 @@ describe Mongoid::Paranoia do
|
|
531
531
|
post.delete!
|
532
532
|
end
|
533
533
|
|
534
|
-
it "
|
534
|
+
it "does not cascade the dependent option" do
|
535
535
|
expect {
|
536
536
|
author.reload
|
537
|
-
}.
|
537
|
+
}.to_not raise_error(Mongoid::Errors::DocumentNotFound)
|
538
538
|
end
|
539
539
|
end
|
540
540
|
end
|
@@ -613,10 +613,10 @@ describe Mongoid::Paranoia do
|
|
613
613
|
post.delete
|
614
614
|
end
|
615
615
|
|
616
|
-
it "
|
616
|
+
it "does not cascade the dependent option" do
|
617
617
|
expect {
|
618
618
|
author.reload
|
619
|
-
}.
|
619
|
+
}.to_not raise_error(Mongoid::Errors::DocumentNotFound)
|
620
620
|
end
|
621
621
|
end
|
622
622
|
|
@@ -637,8 +637,8 @@ describe Mongoid::Paranoia do
|
|
637
637
|
end
|
638
638
|
end
|
639
639
|
|
640
|
-
it "
|
641
|
-
expect(post).
|
640
|
+
it "ignores restrict and destroys the document" do
|
641
|
+
expect(post).to be_destroyed
|
642
642
|
end
|
643
643
|
end
|
644
644
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_paranoia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Durran Jordan
|
@@ -15,20 +15,14 @@ dependencies:
|
|
15
15
|
name: mongoid
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '7.0'
|
21
|
-
- - "<"
|
18
|
+
- - "~>"
|
22
19
|
- !ruby/object:Gem::Version
|
23
20
|
version: '7.3'
|
24
21
|
type: :runtime
|
25
22
|
prerelease: false
|
26
23
|
version_requirements: !ruby/object:Gem::Requirement
|
27
24
|
requirements:
|
28
|
-
- - "
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
version: '7.0'
|
31
|
-
- - "<"
|
25
|
+
- - "~>"
|
32
26
|
- !ruby/object:Gem::Version
|
33
27
|
version: '7.3'
|
34
28
|
- !ruby/object:Gem::Dependency
|