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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f5e32d59286713e858a9dceb94d5f4fb41adeb83
4
- data.tar.gz: bb428d1861efb3f46e00934b27f337b9ea1a5c65
2
+ SHA256:
3
+ metadata.gz: 43d1da1cdc376721364043d5031170e7958fffcb759f9c0e64990a51ba0f5480
4
+ data.tar.gz: b5d1105826ee2edfa11a1b1432230200986ddb8d55b844dc80487c27ccb7cc48
5
5
  SHA512:
6
- metadata.gz: c692991d080ea171430e3114f53c4dea77ebcb1dd0c5cbf74543ffb7433610541070c5da097482608277ac4b75bea095a9c4f9c510b29b0fb46085fae2fff43b
7
- data.tar.gz: 21ccd86425e06c85938fad3121f01ae457b5e1b2061606a2bff1cdc894432bbbe3de728381b87cc5e099403c0511bd2e533347075e713bca972c094c1c41d2a6
6
+ metadata.gz: 306b10fc581eb21195661f6303bf76316854c1cfb5be09c33443b51b4fa865851d4b4c819b7402d7e269684358f62773adbaca4003c7c0b87ef856a9ddcb608e
7
+ data.tar.gz: 1466019a022ce6a6a419d49794ba6c9a00121183dacbe982519174e2b6cf155261e44245bff87711e6333f42cc0a86352dbe4f4ef180f86a3cd8717073c54b6b
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- # Paranoid Documents for Mongoid [![Build Status](https://travis-ci.org/simi/mongoid_paranoia.png?branch=master)](https://travis-ci.org/simi/mongoid_paranoia)[![Gitter chat](https://badges.gitter.im/simi/mongoid_paranoia.png)](https://gitter.im/simi/mongoid_paranoia)
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
 
@@ -97,7 +97,7 @@ module Mongoid
97
97
  alias orig_remove :remove
98
98
 
99
99
  def remove(_ = {})
100
- cascade!
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, metadata|
164
- next unless metadata[:dependent] == :destroy
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 Relations
21
- module Builders
22
- module NestedAttributes
23
- class Many < NestedBuilder
24
- # Destroy the child document, needs to do some checking for embedded
25
- # relations and delay the destroy in case parent validation fails.
26
- #
27
- # @api private
28
- #
29
- # @example Destroy the child.
30
- # builder.destroy(parent, relation, doc)
31
- #
32
- # @param [ Document ] parent The parent document.
33
- # @param [ Proxy ] relation The relation proxy.
34
- # @param [ Document ] doc The doc to destroy.
35
- #
36
- # @since 3.0.10
37
- def destroy(parent, relation, doc)
38
- doc.flagged_for_destroy = true
39
- if !doc.embedded? || parent.new_record? || doc.paranoid?
40
- destroy_document(relation, doc)
41
- else
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 Relations
50
+ module Association
53
51
  module Embedded
54
- # This class handles the behaviour for a document that embeds many other
55
- # documents within in it as an array.
56
- class Many < Relations::Many
57
- # Delete the supplied document from the target. This method is proxied
58
- # in order to reindex the array after the operation occurs.
59
- #
60
- # @example Delete the document from the relation.
61
- # person.addresses.delete(address)
62
- #
63
- # @param [ Document ] document The document to be deleted.
64
- #
65
- # @return [ Document, nil ] The deleted document or nil if nothing deleted.
66
- #
67
- # @since 2.0.0.rc.1
68
- def delete(document)
69
- execute_callback :before_remove, document
70
- doc = target.delete_one(document)
71
- if doc && !_binding?
72
- _unscoped.delete_one(doc) unless doc.paranoid?
73
- if _assigning?
74
- if doc.paranoid?
75
- doc.destroy(suppress: true)
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
- base.add_atomic_pull(doc)
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 Relations
92
+ module Association
95
93
  module Embedded
96
- class Many < Relations::Many
97
- # For use only with Mongoid::Paranoia - will be removed in 4.0.
98
- #
99
- # @example Get the deleted documents from the relation.
100
- # person.paranoid_phones.deleted
101
- #
102
- # @return [ Criteria ] The deleted documents.
103
- #
104
- # @since 3.0.10
105
- def deleted
106
- unscoped.deleted
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
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Paranoia
3
- VERSION = '0.3.0'.freeze
3
+ VERSION = '0.4.0'.freeze
4
4
  end
5
5
  end
@@ -20,6 +20,6 @@ class ParanoidPhone
20
20
  end
21
21
 
22
22
  def halt_me
23
- person.age == 42 ? false : true
23
+ throw :abort if person.age == 42
24
24
  end
25
25
  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: :delete, inverse_of: :post
16
- has_many :titles, dependent: :restrict
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.3.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: 2017-01-05 00:00:00.000000000 Z
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: 6.0.0
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: 6.0.0
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.4.5.1
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/mongoid/nested_attributes_spec.rb
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/app/models/paranoid_phone.rb
98
- - spec/app/models/paranoid_post.rb
99
- - spec/app/models/tag.rb
100
- - spec/app/models/title.rb
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/relations.rb
106
- - spec/app/models/author.rb
107
- - spec/app/models/phone.rb
108
- - spec/spec_helper.rb
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