mongoid_paranoia 0.2.1 → 0.3.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/README.md +9 -17
- data/lib/mongoid/paranoia.rb +9 -14
- data/lib/mongoid/paranoia/version.rb +1 -1
- data/spec/mongoid/nested_attributes_spec.rb +1 -1
- data/spec/spec_helper.rb +4 -2
- metadata +17 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5e32d59286713e858a9dceb94d5f4fb41adeb83
|
4
|
+
data.tar.gz: bb428d1861efb3f46e00934b27f337b9ea1a5c65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c692991d080ea171430e3114f53c4dea77ebcb1dd0c5cbf74543ffb7433610541070c5da097482608277ac4b75bea095a9c4f9c510b29b0fb46085fae2fff43b
|
7
|
+
data.tar.gz: 21ccd86425e06c85938fad3121f01ae457b5e1b2061606a2bff1cdc894432bbbe3de728381b87cc5e099403c0511bd2e533347075e713bca972c094c1c41d2a6
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
# Paranoid Documents for Mongoid
|
1
|
+
# Paranoid Documents for Mongoid [](https://travis-ci.org/simi/mongoid_paranoia)[](https://gitter.im/simi/mongoid_paranoia)
|
2
2
|
|
3
3
|
`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
4
|
|
5
|
-
The `Mongoid::Paranoia` functionality was originally supported in Mongoid itself, but was dropped from version 4.0.0 onwards. This gem was extracted from the [Mongoid 3.0.0-stable branch](https://github.com/mongoid/mongoid/tree/3.0.0-stable). This gem should not be used with Mongoid versions 3.x and prior.
|
5
|
+
The `Mongoid::Paranoia` functionality was originally supported in Mongoid itself, but was dropped from version 4.0.0 onwards. This gem was extracted from the [Mongoid 3.0.0-stable branch](https://github.com/mongoid/mongoid/tree/3.0.0-stable). This gem should not be used with Mongoid versions 3.x and prior. Current master branch targeted on Mongoid 6.0. With release 0.3.0 Mongoid 4 and 5 versions will be dropped.
|
6
6
|
|
7
7
|
**Caution:** This repo/gem `mongoid_paranoia` (underscored) is different than [mongoid-paranoia](https://github.com/haihappen/mongoid-paranoia) (hyphenated). The goal of `mongoid-paranoia` (hyphenated) is to stay API compatible and it only accepts security fixes.
|
8
8
|
|
@@ -14,21 +14,6 @@ Add this line to your application's Gemfile:
|
|
14
14
|
gem 'mongoid_paranoia'
|
15
15
|
```
|
16
16
|
|
17
|
-
## Changes in 4.0
|
18
|
-
|
19
|
-
### Uniqueness validator is not overriden
|
20
|
-
|
21
|
-
#### Old syntax:
|
22
|
-
```ruby
|
23
|
-
validates_uniqueness_of :title
|
24
|
-
validates :title, :uniqueness => true
|
25
|
-
```
|
26
|
-
|
27
|
-
#### New syntax:
|
28
|
-
```ruby
|
29
|
-
validates :title, uniqueness: { conditions: -> { where(deleted_at: nil) } }
|
30
|
-
```
|
31
|
-
|
32
17
|
## Usage
|
33
18
|
|
34
19
|
```ruby
|
@@ -67,6 +52,13 @@ Mongoid::Paranoia.configure do |c|
|
|
67
52
|
end
|
68
53
|
```
|
69
54
|
|
55
|
+
### Validations
|
56
|
+
#### You need override uniqueness validates
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
validates :title, uniqueness: { conditions: -> { where(deleted_at: nil) } }
|
60
|
+
```
|
61
|
+
|
70
62
|
### Callbacks
|
71
63
|
|
72
64
|
#### Restore
|
data/lib/mongoid/paranoia.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require 'mongoid/compatibility'
|
3
2
|
require 'mongoid/paranoia/monkey_patches'
|
4
3
|
require 'mongoid/paranoia/configuration'
|
5
4
|
require 'active_support'
|
@@ -95,15 +94,17 @@ module Mongoid
|
|
95
94
|
# @return [ true ] True.
|
96
95
|
#
|
97
96
|
# @since 1.0.0
|
98
|
-
|
97
|
+
alias orig_remove :remove
|
98
|
+
|
99
|
+
def remove(_ = {})
|
99
100
|
cascade!
|
100
101
|
time = self.deleted_at = Time.now
|
101
|
-
_paranoia_update(
|
102
|
+
_paranoia_update('$set' => { paranoid_field => time })
|
102
103
|
@destroyed = true
|
103
104
|
true
|
104
105
|
end
|
105
|
-
|
106
|
-
alias
|
106
|
+
|
107
|
+
alias delete :remove
|
107
108
|
|
108
109
|
# Delete the paranoid +Document+ from the database completely.
|
109
110
|
#
|
@@ -114,7 +115,7 @@ module Mongoid
|
|
114
115
|
#
|
115
116
|
# @since 1.0.0
|
116
117
|
def delete!
|
117
|
-
|
118
|
+
orig_remove
|
118
119
|
end
|
119
120
|
|
120
121
|
# Determines if this document is destroyed.
|
@@ -193,16 +194,10 @@ module Mongoid
|
|
193
194
|
embedded? ? "#{atomic_position}.#{field}" : field
|
194
195
|
end
|
195
196
|
|
196
|
-
# Update value in the collection (compatibility layer for Mongoid 4/5).
|
197
|
-
#
|
198
197
|
# @return [ Object ] Update result.
|
198
|
+
#
|
199
199
|
def _paranoia_update(value)
|
200
|
-
|
201
|
-
if Mongoid::Compatibility::Version.mongoid5?
|
202
|
-
query.update_one(value)
|
203
|
-
else
|
204
|
-
query.update(value)
|
205
|
-
end
|
200
|
+
paranoid_collection.find(atomic_selector).update_one(value)
|
206
201
|
end
|
207
202
|
end
|
208
203
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,7 +4,6 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
|
4
4
|
require "mongoid"
|
5
5
|
require "mongoid/paranoia"
|
6
6
|
require "rspec"
|
7
|
-
Dir[File.join(File.dirname(__FILE__), "app/models/*.rb")].each{ |f| require f }
|
8
7
|
|
9
8
|
# These environment variables can be set if wanting to test against a database
|
10
9
|
# that is not on the local machine.
|
@@ -33,6 +32,7 @@ end
|
|
33
32
|
|
34
33
|
# Set the database that the spec suite connects to.
|
35
34
|
Mongoid.configure do |config|
|
35
|
+
config.belongs_to_required_by_default = false
|
36
36
|
config.connect_to(database_id)
|
37
37
|
end
|
38
38
|
|
@@ -55,7 +55,7 @@ RSpec.configure do |config|
|
|
55
55
|
|
56
56
|
config.before(:all) do
|
57
57
|
Mongoid.logger.level = Logger::INFO
|
58
|
-
Mongo::Logger.logger.level = Logger::INFO
|
58
|
+
Mongo::Logger.logger.level = Logger::INFO
|
59
59
|
end
|
60
60
|
|
61
61
|
config.after(:all) do
|
@@ -71,3 +71,5 @@ end
|
|
71
71
|
ActiveSupport::Inflector.inflections do |inflect|
|
72
72
|
inflect.singular("address_components", "address_component")
|
73
73
|
end
|
74
|
+
|
75
|
+
Dir[File.join(File.dirname(__FILE__), "app/models/*.rb")].each{ |f| require f }
|
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.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Durran Jordan
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-01-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mongoid
|
@@ -17,28 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 6.0.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:
|
28
|
-
- !ruby/object:Gem::Dependency
|
29
|
-
name: mongoid-compatibility
|
30
|
-
requirement: !ruby/object:Gem::Requirement
|
31
|
-
requirements:
|
32
|
-
- - ">="
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: '0'
|
35
|
-
type: :runtime
|
36
|
-
prerelease: false
|
37
|
-
version_requirements: !ruby/object:Gem::Requirement
|
38
|
-
requirements:
|
39
|
-
- - ">="
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
version: '0'
|
27
|
+
version: 6.0.0
|
42
28
|
description: There may be times when you don't want documents to actually get deleted
|
43
29
|
from the database, but "flagged" as deleted. Mongoid provides a Paranoia module
|
44
30
|
to give you just that.
|
@@ -102,21 +88,21 @@ specification_version: 4
|
|
102
88
|
summary: Paranoid documents
|
103
89
|
test_files:
|
104
90
|
- perf/scope.rb
|
105
|
-
- spec/
|
106
|
-
- spec/
|
107
|
-
- spec/
|
108
|
-
- spec/
|
91
|
+
- spec/mongoid/nested_attributes_spec.rb
|
92
|
+
- spec/mongoid/scoping_spec.rb
|
93
|
+
- spec/mongoid/configuration_spec.rb
|
94
|
+
- spec/mongoid/paranoia_spec.rb
|
95
|
+
- spec/mongoid/document_spec.rb
|
96
|
+
- spec/mongoid/validatable/uniqueness_spec.rb
|
109
97
|
- spec/app/models/paranoid_phone.rb
|
110
|
-
- spec/app/models/fish.rb
|
111
|
-
- spec/app/models/person.rb
|
112
|
-
- spec/app/models/phone.rb
|
113
98
|
- spec/app/models/paranoid_post.rb
|
114
99
|
- spec/app/models/tag.rb
|
100
|
+
- spec/app/models/title.rb
|
101
|
+
- spec/app/models/person.rb
|
102
|
+
- spec/app/models/address.rb
|
103
|
+
- spec/app/models/appointment.rb
|
104
|
+
- spec/app/models/fish.rb
|
115
105
|
- spec/app/models/relations.rb
|
106
|
+
- spec/app/models/author.rb
|
107
|
+
- spec/app/models/phone.rb
|
116
108
|
- spec/spec_helper.rb
|
117
|
-
- spec/mongoid/paranoia_spec.rb
|
118
|
-
- spec/mongoid/validatable/uniqueness_spec.rb
|
119
|
-
- spec/mongoid/nested_attributes_spec.rb
|
120
|
-
- spec/mongoid/document_spec.rb
|
121
|
-
- spec/mongoid/configuration_spec.rb
|
122
|
-
- spec/mongoid/scoping_spec.rb
|