mongoid_cleaner 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +3 -0
- data/README.md +13 -6
- data/gemfiles/mongoid4.gemfile +5 -0
- data/gemfiles/mongoid5.gemfile +5 -0
- data/lib/mongoid_cleaner/version.rb +1 -1
- data/lib/mongoid_cleaner.rb +22 -4
- data/mongoid_cleaner.gemspec +1 -1
- metadata +9 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d8c7375290440e533630aba4b66a36217cd933b
|
4
|
+
data.tar.gz: a74702cb43805411e46c4b3f681d383e0f7b6bb9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f57547909b9fa0bc81f0529b7679f56dc454a9e0724a32caca262e7d4325fa7012410cb9c2f597e994ae6e7286dc51c7fbfe5bf12a22842436dd325e24aa376
|
7
|
+
data.tar.gz: b6ff6fcc604dfd3fc398f078e016af7b42477cfbd2e165411f264ac69e84077b48f18447917a01a165ca8a9cb148f84667fbea344f7e9bf014d586dcf92449ee
|
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,16 +1,23 @@
|
|
1
1
|
# MongoidCleaner
|
2
|
+
[![Build Status](https://travis-ci.org/td-berlin/mongoid_cleaner.svg)](https://travis-ci.org/td-berlin/mongoid_cleaner)
|
2
3
|
|
3
|
-
|
4
|
+
MongoidCleaner is an alternative for [DatabaseCleaner](https://github.com/DatabaseCleaner/database_cleaner)
|
5
|
+
for projects using [MongoDB](https://www.mongodb.org/) along with [Mongoid](http://mongoid.org/en/mongoid/index.html).
|
6
|
+
Besides the `truncate` strategy, this gem also provides faster `drop` strategy. It runs with Mongoid versions 4 and 5.
|
4
7
|
|
5
|
-
MongoidCleaner with drop and truncation strategy
|
6
8
|
|
7
9
|
## Why?
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
+
DatabaseCleaner always served our needs well, unfortunately it didn't support [MongoDB 3 running on Wired Tiger](https://github.com/DatabaseCleaner/database_cleaner/pull/343)
|
12
|
+
for quite some time, so we decided to build our own specialised solution.
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
+
Also, removing all the documents from a collection requires much more work: Freeing the document's storage, clearing the index entries that point to the document, etc..
|
15
|
+
The benefit of simply dropping a collection is that it is much faster.
|
16
|
+
|
17
|
+
## Possible drawbacks
|
18
|
+
|
19
|
+
We haven't experienced any problems so far, but dropping a collection will also remove the collections indexes.
|
20
|
+
Feel free to report any issues related to that.
|
14
21
|
|
15
22
|
## Installation
|
16
23
|
|
data/lib/mongoid_cleaner.rb
CHANGED
@@ -8,6 +8,10 @@ module MongoidCleaner
|
|
8
8
|
class << self
|
9
9
|
attr_reader :strategy
|
10
10
|
|
11
|
+
def mongoid_version
|
12
|
+
@mongoid_version ||= Mongoid::VERSION.split('.').first.to_i
|
13
|
+
end
|
14
|
+
|
11
15
|
def available_strategies
|
12
16
|
@available_strategies ||= %w(truncate drop)
|
13
17
|
end
|
@@ -28,14 +32,24 @@ module MongoidCleaner
|
|
28
32
|
@session ||= Mongoid.default_session
|
29
33
|
end
|
30
34
|
|
31
|
-
#
|
32
|
-
|
35
|
+
# return with mongoid 5 `Mongo::Operation::Result`
|
36
|
+
# return with mongoid 4 `BSON::Document`
|
37
|
+
def collections_filter
|
33
38
|
session.command(
|
34
39
|
listCollections: 1,
|
35
40
|
filter: {
|
36
41
|
name:
|
37
42
|
{ '$not' => /.?system\.|\$/ }
|
38
|
-
})
|
43
|
+
})
|
44
|
+
end
|
45
|
+
|
46
|
+
# @return Array mongoid collections names
|
47
|
+
def collections
|
48
|
+
if mongoid_version > 4
|
49
|
+
collections_filter.first[:cursor][:firstBatch].map { |c| c['name'] }
|
50
|
+
else
|
51
|
+
collections_filter['cursor']['firstBatch'].map { |c| c['name'] }
|
52
|
+
end
|
39
53
|
end
|
40
54
|
|
41
55
|
def collections_with_options
|
@@ -56,7 +70,11 @@ module MongoidCleaner
|
|
56
70
|
|
57
71
|
# @return Boolean
|
58
72
|
def truncate
|
59
|
-
|
73
|
+
if mongoid_version > 4
|
74
|
+
collections_with_options.each { |c| session[c].find.delete_many }
|
75
|
+
else
|
76
|
+
collections_with_options.each { |c| session[c].find.remove_all }
|
77
|
+
end
|
60
78
|
true
|
61
79
|
end
|
62
80
|
|
data/mongoid_cleaner.gemspec
CHANGED
@@ -21,5 +21,5 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency 'bundler', '~> 1.9'
|
22
22
|
spec.add_development_dependency 'rake', '~> 10.0'
|
23
23
|
spec.add_development_dependency 'rubocop', '~> 0.31'
|
24
|
-
spec.add_dependency 'mongoid', '
|
24
|
+
spec.add_dependency 'mongoid', '>= 4.0'
|
25
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_cleaner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TD Dashboys
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -56,14 +56,14 @@ dependencies:
|
|
56
56
|
name: mongoid
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '4.0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '4.0'
|
69
69
|
description:
|
@@ -74,12 +74,16 @@ extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
76
|
- ".gitignore"
|
77
|
+
- ".rubocop.yml"
|
77
78
|
- ".travis.yml"
|
79
|
+
- CHANGELOG.md
|
78
80
|
- Gemfile
|
79
81
|
- LICENSE.txt
|
80
82
|
- README.md
|
81
83
|
- Rakefile
|
82
84
|
- configs/mongodb-wiredtiger.conf
|
85
|
+
- gemfiles/mongoid4.gemfile
|
86
|
+
- gemfiles/mongoid5.gemfile
|
83
87
|
- lib/mongoid_cleaner.rb
|
84
88
|
- lib/mongoid_cleaner/version.rb
|
85
89
|
- mongoid_cleaner.gemspec
|
@@ -103,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
107
|
version: '0'
|
104
108
|
requirements: []
|
105
109
|
rubyforge_project:
|
106
|
-
rubygems_version: 2.4.5
|
110
|
+
rubygems_version: 2.4.5.1
|
107
111
|
signing_key:
|
108
112
|
specification_version: 4
|
109
113
|
summary: MongoidCleaner with drop and truncation strategy
|