Sha256: 217b550ed063614824c019ddd13c94007bb9b5c13aee634dcf08de8402107930

Contents?: true

Size: 1.07 KB

Versions: 15

Compression:

Stored size: 1.07 KB

Contents

require 'database_cleaner/moped/base'
require 'database_cleaner/generic/truncation'

module DatabaseCleaner
  module Moped
    module TruncationBase
      include ::DatabaseCleaner::Moped::Base
      include ::DatabaseCleaner::Generic::Truncation

      def clean
        if @only
          collections.each { |c| session[c].find.remove_all if @only.include?(c) }
        else
          collections.each { |c| session[c].find.remove_all unless @tables_to_exclude.include?(c) }
        end
        true
      end

      private

      def collections
        if db != :default
          session.use(db)
        end

        if db_version.split('.').first.to_i >= 3
          session.command(listCollections: 1, filter: { 'name' => { '$not' => /.?system\.|\$/ } })['cursor']['firstBatch'].map do |collection|
            collection['name']
          end
        else
          session['system.namespaces'].find(name: { '$not' => /\.system\.|\$/ }).to_a.map do |collection|
            _, name = collection['name'].split('.', 2)
            name
          end
        end
      end

    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
database_cleaner-1.7.0 lib/database_cleaner/moped/truncation_base.rb
database_cleaner-1.6.2 lib/database_cleaner/moped/truncation_base.rb
database_cleaner-1.6.1 lib/database_cleaner/moped/truncation_base.rb
database_cleaner-1.6.0 lib/database_cleaner/moped/truncation_base.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/database_cleaner-1.5.3/lib/database_cleaner/moped/truncation_base.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/database_cleaner-1.5.3/lib/database_cleaner/moped/truncation_base.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/database_cleaner-1.5.3/lib/database_cleaner/moped/truncation_base.rb
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/database_cleaner-1.5.3/lib/database_cleaner/moped/truncation_base.rb
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/database_cleaner-1.5.3/lib/database_cleaner/moped/truncation_base.rb
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/database_cleaner-1.5.3/lib/database_cleaner/moped/truncation_base.rb
autocompl-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/database_cleaner-1.5.3/lib/database_cleaner/moped/truncation_base.rb
database_cleaner-1.5.3 lib/database_cleaner/moped/truncation_base.rb
database_cleaner-1.5.2 lib/database_cleaner/moped/truncation_base.rb
database_cleaner-1.5.1 lib/database_cleaner/moped/truncation_base.rb
database_cleaner-1.5.0 lib/database_cleaner/moped/truncation_base.rb