mongoid_paranoia 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +2 -1
- data/lib/mongoid/paranoia.rb +3 -3
- data/lib/mongoid/paranoia/monkey_patches.rb +68 -68
- data/lib/mongoid/paranoia/version.rb +1 -1
- data/spec/app/models/paranoid_phone.rb +1 -1
- data/spec/app/models/paranoid_post.rb +2 -2
- metadata +19 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 43d1da1cdc376721364043d5031170e7958fffcb759f9c0e64990a51ba0f5480
|
4
|
+
data.tar.gz: b5d1105826ee2edfa11a1b1432230200986ddb8d55b844dc80487c27ccb7cc48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 306b10fc581eb21195661f6303bf76316854c1cfb5be09c33443b51b4fa865851d4b4c819b7402d7e269684358f62773adbaca4003c7c0b87ef856a9ddcb608e
|
7
|
+
data.tar.gz: 1466019a022ce6a6a419d49794ba6c9a00121183dacbe982519174e2b6cf155261e44245bff87711e6333f42cc0a86352dbe4f4ef180f86a3cd8717073c54b6b
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
# Paranoid Documents for Mongoid
|
1
|
+
# Paranoid Documents for Mongoid
|
2
|
+
[![Build Status](https://travis-ci.org/simi/mongoid_paranoia.svg?branch=master)](https://travis-ci.org/simi/mongoid_paranoia) [![Gem Version](https://img.shields.io/gem/v/mongoid_paranoia.svg)](https://rubygems.org/gems/mongoid_paranoia) [![Gitter chat](https://badges.gitter.im/simi/mongoid_paranoia.svg)](https://gitter.im/simi/mongoid_paranoia)
|
2
3
|
|
3
4
|
`Mongoid::Paranoia` enables a "soft delete" of Mongoid documents. Instead of being removed from the database, paranoid docs are flagged with a `deleted_at` timestamp and are ignored from queries by default.
|
4
5
|
|
data/lib/mongoid/paranoia.rb
CHANGED
@@ -97,7 +97,7 @@ module Mongoid
|
|
97
97
|
alias orig_remove :remove
|
98
98
|
|
99
99
|
def remove(_ = {})
|
100
|
-
|
100
|
+
return false unless catch(:abort) { apply_delete_dependencies! }
|
101
101
|
time = self.deleted_at = Time.now
|
102
102
|
_paranoia_update('$set' => { paranoid_field => time })
|
103
103
|
@destroyed = true
|
@@ -160,8 +160,8 @@ module Mongoid
|
|
160
160
|
end
|
161
161
|
|
162
162
|
def restore_relations
|
163
|
-
self.relations.each_pair do |name,
|
164
|
-
next unless
|
163
|
+
self.relations.each_pair do |name, association|
|
164
|
+
next unless association.dependent == :destroy
|
165
165
|
relation = self.send(name)
|
166
166
|
if relation.present? && relation.paranoid?
|
167
167
|
Array.wrap(relation).each do |doc|
|
@@ -17,30 +17,28 @@ end
|
|
17
17
|
Mongoid::Document.send(:include, Mongoid::Paranoia::Document)
|
18
18
|
|
19
19
|
module Mongoid
|
20
|
-
module
|
21
|
-
module
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
parent.flagged_destroys.push(->{ destroy_document(relation, doc) })
|
43
|
-
end
|
20
|
+
module Association
|
21
|
+
module Nested
|
22
|
+
class Many
|
23
|
+
# Destroy the child document, needs to do some checking for embedded
|
24
|
+
# relations and delay the destroy in case parent validation fails.
|
25
|
+
#
|
26
|
+
# @api private
|
27
|
+
#
|
28
|
+
# @example Destroy the child.
|
29
|
+
# builder.destroy(parent, relation, doc)
|
30
|
+
#
|
31
|
+
# @param [ Document ] parent The parent document.
|
32
|
+
# @param [ Proxy ] relation The relation proxy.
|
33
|
+
# @param [ Document ] doc The doc to destroy.
|
34
|
+
#
|
35
|
+
# @since 3.0.10
|
36
|
+
def destroy(parent, relation, doc)
|
37
|
+
doc.flagged_for_destroy = true
|
38
|
+
if !doc.embedded? || parent.new_record? || doc.paranoid?
|
39
|
+
destroy_document(relation, doc)
|
40
|
+
else
|
41
|
+
parent.flagged_destroys.push(->{ destroy_document(relation, doc) })
|
44
42
|
end
|
45
43
|
end
|
46
44
|
end
|
@@ -49,41 +47,41 @@ module Mongoid
|
|
49
47
|
end
|
50
48
|
|
51
49
|
module Mongoid
|
52
|
-
module
|
50
|
+
module Association
|
53
51
|
module Embedded
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
52
|
+
class EmbedsMany
|
53
|
+
class Proxy < Association::Many
|
54
|
+
# Delete the supplied document from the target. This method is proxied
|
55
|
+
# in order to reindex the array after the operation occurs.
|
56
|
+
#
|
57
|
+
# @example Delete the document from the relation.
|
58
|
+
# person.addresses.delete(address)
|
59
|
+
#
|
60
|
+
# @param [ Document ] document The document to be deleted.
|
61
|
+
#
|
62
|
+
# @return [ Document, nil ] The deleted document or nil if nothing deleted.
|
63
|
+
#
|
64
|
+
# @since 2.0.0.rc.1
|
65
|
+
def delete(document)
|
66
|
+
execute_callback :before_remove, document
|
67
|
+
doc = _target.delete_one(document)
|
68
|
+
if doc && !_binding?
|
69
|
+
_unscoped.delete_one(doc) unless doc.paranoid?
|
70
|
+
if _assigning?
|
71
|
+
if doc.paranoid?
|
72
|
+
doc.destroy(suppress: true)
|
73
|
+
else
|
74
|
+
_base.add_atomic_pull(doc)
|
75
|
+
end
|
76
76
|
else
|
77
|
-
|
77
|
+
doc.delete(suppress: true)
|
78
|
+
unbind_one(doc)
|
78
79
|
end
|
79
|
-
else
|
80
|
-
doc.delete(suppress: true)
|
81
|
-
unbind_one(doc)
|
82
80
|
end
|
81
|
+
reindex
|
82
|
+
execute_callback :after_remove, document
|
83
|
+
doc
|
83
84
|
end
|
84
|
-
reindex
|
85
|
-
execute_callback :after_remove, document
|
86
|
-
doc
|
87
85
|
end
|
88
86
|
end
|
89
87
|
end
|
@@ -91,22 +89,24 @@ module Mongoid
|
|
91
89
|
end
|
92
90
|
|
93
91
|
module Mongoid
|
94
|
-
module
|
92
|
+
module Association
|
95
93
|
module Embedded
|
96
|
-
class
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
94
|
+
class EmbedsMany
|
95
|
+
class Proxy < Association::Many
|
96
|
+
# For use only with Mongoid::Paranoia - will be removed in 4.0.
|
97
|
+
#
|
98
|
+
# @example Get the deleted documents from the relation.
|
99
|
+
# person.paranoid_phones.deleted
|
100
|
+
#
|
101
|
+
# @return [ Criteria ] The deleted documents.
|
102
|
+
#
|
103
|
+
# @since 3.0.10
|
104
|
+
def deleted
|
105
|
+
unscoped.deleted
|
106
|
+
end
|
107
|
+
# This class handles the behaviour for a document that embeds many other
|
108
|
+
# documents within in it as an array.
|
107
109
|
end
|
108
|
-
# This class handles the behaviour for a document that embeds many other
|
109
|
-
# documents within in it as an array.
|
110
110
|
end
|
111
111
|
end
|
112
112
|
end
|
@@ -12,8 +12,8 @@ class ParanoidPost
|
|
12
12
|
belongs_to :person
|
13
13
|
|
14
14
|
has_and_belongs_to_many :tags
|
15
|
-
has_many :authors, dependent: :
|
16
|
-
has_many :titles, dependent: :
|
15
|
+
has_many :authors, dependent: :delete_all, inverse_of: :post
|
16
|
+
has_many :titles, dependent: :restrict_with_error
|
17
17
|
|
18
18
|
scope :recent, -> {where(created_at: { "$lt" => Time.now, "$gt" => 30.days.ago })}
|
19
19
|
|
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.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Durran Jordan
|
@@ -9,22 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2019-05-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mongoid
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
18
|
+
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: '7.0'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - "
|
25
|
+
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: '7.0'
|
28
28
|
description: There may be times when you don't want documents to actually get deleted
|
29
29
|
from the database, but "flagged" as deleted. Mongoid provides a Paranoia module
|
30
30
|
to give you just that.
|
@@ -82,27 +82,27 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
82
|
version: '0'
|
83
83
|
requirements: []
|
84
84
|
rubyforge_project:
|
85
|
-
rubygems_version: 2.
|
85
|
+
rubygems_version: 2.7.6
|
86
86
|
signing_key:
|
87
87
|
specification_version: 4
|
88
88
|
summary: Paranoid documents
|
89
89
|
test_files:
|
90
90
|
- perf/scope.rb
|
91
|
-
- spec/
|
92
|
-
- spec/mongoid/scoping_spec.rb
|
93
|
-
- spec/mongoid/configuration_spec.rb
|
91
|
+
- spec/spec_helper.rb
|
94
92
|
- spec/mongoid/paranoia_spec.rb
|
93
|
+
- spec/mongoid/configuration_spec.rb
|
95
94
|
- spec/mongoid/document_spec.rb
|
95
|
+
- spec/mongoid/nested_attributes_spec.rb
|
96
96
|
- spec/mongoid/validatable/uniqueness_spec.rb
|
97
|
-
- spec/
|
98
|
-
- spec/app/models/
|
99
|
-
- spec/app/models/
|
100
|
-
- spec/app/models/
|
97
|
+
- spec/mongoid/scoping_spec.rb
|
98
|
+
- spec/app/models/author.rb
|
99
|
+
- spec/app/models/relations.rb
|
100
|
+
- spec/app/models/phone.rb
|
101
101
|
- spec/app/models/person.rb
|
102
|
-
- spec/app/models/address.rb
|
103
102
|
- spec/app/models/appointment.rb
|
103
|
+
- spec/app/models/title.rb
|
104
104
|
- spec/app/models/fish.rb
|
105
|
-
- spec/app/models/
|
106
|
-
- spec/app/models/
|
107
|
-
- spec/app/models/
|
108
|
-
- spec/
|
105
|
+
- spec/app/models/address.rb
|
106
|
+
- spec/app/models/paranoid_phone.rb
|
107
|
+
- spec/app/models/paranoid_post.rb
|
108
|
+
- spec/app/models/tag.rb
|