mongoid_cleaner 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fdc85738b916058da39a76bb73892bafd80e3c58
4
+ data.tar.gz: 2e37d7083ae4c4eb0d9ff567197c71bed6a5defe
5
+ SHA512:
6
+ metadata.gz: eaf57c59b37c224831b08daeba6bf308a4d8f2f46599fce644567b5f68824cef628d0439d30f4773f5ca9da451143366ee598593e120b7b82ffba92b902f0369
7
+ data.tar.gz: 47c7a47d4244a2af40f6e2c95d0b65bf2cf14e49d6fae34142399ec6d2d796bc4f2c953d4f40775d53d7a25292774843c75d233773de90af05b2eb1c34eb9dbc
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,30 @@
1
+ sudo: false
2
+ bundler_args: --jobs=3 --retry=3
3
+ cache:
4
+ - bundler
5
+ before_install:
6
+ - gem update --remote bundler
7
+ env:
8
+ matrix:
9
+ - MONGODB=3.0.3 CONFIG="--config /tmp/mongodb-wiredtiger.conf"
10
+ - MONGODB=3.0.3 CONFIG=""
11
+ before_script:
12
+ - cp configs/mongodb-wiredtiger.conf /tmp/mongodb-wiredtiger.conf
13
+ - wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-${MONGODB}.tgz -O /tmp/mongodb.tgz
14
+ - tar -xvf /tmp/mongodb.tgz
15
+ - mkdir /tmp/data
16
+ - ${PWD}/mongodb-linux-x86_64-${MONGODB}/bin/mongod --version
17
+ - ${PWD}/mongodb-linux-x86_64-${MONGODB}/bin/mongod --dbpath /tmp/data --bind_ip 127.0.0.1 $CONFIG &> /dev/null &
18
+ language: ruby
19
+ rvm:
20
+ - 2.1
21
+ - 2.2
22
+ - jruby
23
+ - ruby-head
24
+ matrix:
25
+ allow_failures:
26
+ - rvm: ruby-head
27
+ fast_finish: true
28
+ script:
29
+ - bundle exec rake
30
+ - bundle exec rubocop
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mongoid_cleaner.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Laurent Arnoud
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # MongoidCleaner
2
+
3
+ ![Build Status](https://magnum.travis-ci.com/td-berlin/mongoid_cleaner.svg?token=1Pjyqv334JwTadXqcays&branch=master)
4
+
5
+ MongoidCleaner with drop and truncation strategy
6
+
7
+ ## Why?
8
+
9
+ * [database_cleaner](https://github.com/DatabaseCleaner/database_cleaner) exists
10
+ but it don't support [MongoDB 3](https://github.com/DatabaseCleaner/database_cleaner/issues/348).
11
+
12
+ * Also we discovered that droping collection is more faster than truncation
13
+ strategy.
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'mongoid_cleaner'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install mongoid_cleaner
30
+
31
+ ## Usage
32
+
33
+ With rspec:
34
+
35
+ ~~~ ruby
36
+ RSpec.configure do |config|
37
+ config.before(:suite) do
38
+ MongoidCleaner.strategy = :drop
39
+ end
40
+
41
+ config.around(:each) do |example|
42
+ MongoidCleaner.cleaning do
43
+ example.run
44
+ end
45
+ end
46
+ end
47
+ ~~~
48
+
49
+ Without rspec:
50
+
51
+ ~~~ ruby
52
+ MongoidCleaner.strategy = 'drop', { only: %w(users) }
53
+ MongoidCleaner.clean
54
+ # dirty mongo
55
+ MongoidCleaner.strategy = 'truncate', { except: %w(users) }
56
+ MongoidCleaner.clean
57
+ ~~~
58
+
59
+ ## Development
60
+
61
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
62
+
63
+ ## Tests
64
+
65
+ Unit testing:
66
+
67
+ ~~~
68
+ bundle exec rake test
69
+ ~~~
70
+
71
+ Code style:
72
+
73
+ ~~~
74
+ bundle exec rubocop
75
+ ~~~
76
+
77
+ ## Contributing
78
+
79
+ 1. Fork it ( https://github.com/td-berlin/mongoid_cleaner/fork )
80
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
81
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
82
+ 4. Push to the branch (`git push origin my-new-feature`)
83
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ task default: :test
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'test'
8
+ t.test_files = FileList['test/test*.rb']
9
+ t.verbose = true
10
+ end
@@ -0,0 +1,2 @@
1
+ storage:
2
+ engine: wiredTiger
@@ -0,0 +1,4 @@
1
+ # :nodoc:
2
+ module MongoidCleaner
3
+ VERSION = '1.0.0'
4
+ end
@@ -0,0 +1,73 @@
1
+ require 'mongoid_cleaner/version'
2
+
3
+ # MongoidCleaner base module
4
+ module MongoidCleaner
5
+ # strategy is unknown
6
+ class UnknownStrategySpecified < ArgumentError; end
7
+
8
+ class << self
9
+ attr_reader :strategy
10
+
11
+ def available_strategies
12
+ @available_strategies ||= %w(truncate drop)
13
+ end
14
+
15
+ # @arg args strategy String
16
+ # @arg args options Hash
17
+ def strategy=(*options)
18
+ strategy = options.flatten.shift.to_s
19
+ @options = options.flatten.last if options.flatten.last.is_a? Hash
20
+ if available_strategies.include? strategy
21
+ @strategy = strategy
22
+ else
23
+ fail UnknownStrategySpecified
24
+ end
25
+ end
26
+
27
+ def session
28
+ @session ||= Mongoid.default_session
29
+ end
30
+
31
+ # @return Array mongoid collections
32
+ def collections
33
+ session.command(
34
+ listCollections: 1,
35
+ filter: {
36
+ name:
37
+ { '$not' => /.?system\.|\$/ }
38
+ })['cursor']['firstBatch'].map { |c| c['name'] }
39
+ end
40
+
41
+ def collections_with_options
42
+ return collections unless @options
43
+ return collections if @options.empty?
44
+ if @options[:only]
45
+ collections.select { |c| @options[:only].include? c }
46
+ elsif @options[:except]
47
+ collections.select { |c| !@options[:except].include? c }
48
+ end
49
+ end
50
+
51
+ # @return Boolean
52
+ def drop
53
+ collections_with_options.each { |c| session[c].drop }
54
+ true
55
+ end
56
+
57
+ # @return Boolean
58
+ def truncate
59
+ collections_with_options.each { |c| session[c].find.remove_all }
60
+ true
61
+ end
62
+
63
+ # call truncate or drop method
64
+ def clean
65
+ public_send strategy
66
+ end
67
+
68
+ def cleaning
69
+ clean
70
+ yield if block_given?
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mongoid_cleaner/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'mongoid_cleaner'
8
+ spec.version = MongoidCleaner::VERSION
9
+ spec.authors = ['TD Dashboys']
10
+ spec.email = ['dashboys@td-berlin.com']
11
+
12
+ spec.summary = 'MongoidCleaner with drop and truncation strategy'
13
+ spec.homepage = 'https://github.com/td-berlin/mongoid_cleaner'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.9'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rubocop', '~> 0.31'
24
+ spec.add_dependency 'mongoid', '~> 4.0'
25
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongoid_cleaner
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - TD Dashboys
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.31'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.31'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mongoid
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.0'
69
+ description:
70
+ email:
71
+ - dashboys@td-berlin.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - configs/mongodb-wiredtiger.conf
83
+ - lib/mongoid_cleaner.rb
84
+ - lib/mongoid_cleaner/version.rb
85
+ - mongoid_cleaner.gemspec
86
+ homepage: https://github.com/td-berlin/mongoid_cleaner
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.4.5
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: MongoidCleaner with drop and truncation strategy
110
+ test_files: []