Sha256: 77e1a758581676db1fd57b5a3051df3fe6788d33c1e0bca961b3ce4eef1ba57b

Contents?: true

Size: 913 Bytes

Versions: 18

Compression:

Stored size: 913 Bytes

Contents

module DatabaseCleaner
  module Mongo2
    module TruncationMixin

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

      private

      def database
        if @db.nil? || @db == :default
          ::Mongoid::Clients.default
        else
          ::Mongoid::Clients.with_name(@db)
        end
      end

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

        database.collections.collect { |c| c.namespace.split('.',2)[1] }

        # database['system.namespaces'].find(:name => { '$not' => /\.system\.|\$/ }).to_a.map do |collection|
        #   _, name = collection['name'].split('.', 2)
        #   name
        # end
      end

    end
  end
end

Version data entries

18 entries across 18 versions & 3 rubygems

Version Path
database_cleaner-1.8.1 adapters/database_cleaner-mongoid/lib/database_cleaner/mongo2/truncation_mixin.rb
database_cleaner-1.8.0 adapters/database_cleaner-mongoid/lib/database_cleaner/mongo2/truncation_mixin.rb
database_cleaner-mongoid-1.8.0 lib/database_cleaner/mongo2/truncation_mixin.rb
database_cleaner-1.8.0.beta adapters/database_cleaner-mongoid/lib/database_cleaner/mongo2/truncation_mixin.rb
database_cleaner-mongoid-1.8.0.beta lib/database_cleaner/mongo2/truncation_mixin.rb
database_cleaner-1.7.0 lib/database_cleaner/mongo2/truncation_mixin.rb
database_cleaner-1.6.2 lib/database_cleaner/mongo2/truncation_mixin.rb
database_cleaner-1.6.1 lib/database_cleaner/mongo2/truncation_mixin.rb
database_cleaner-1.6.0 lib/database_cleaner/mongo2/truncation_mixin.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/database_cleaner-1.5.3/lib/database_cleaner/mongo2/truncation_mixin.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/database_cleaner-1.5.3/lib/database_cleaner/mongo2/truncation_mixin.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/database_cleaner-1.5.3/lib/database_cleaner/mongo2/truncation_mixin.rb
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/database_cleaner-1.5.3/lib/database_cleaner/mongo2/truncation_mixin.rb
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/database_cleaner-1.5.3/lib/database_cleaner/mongo2/truncation_mixin.rb
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/database_cleaner-1.5.3/lib/database_cleaner/mongo2/truncation_mixin.rb
autocompl-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/database_cleaner-1.5.3/lib/database_cleaner/mongo2/truncation_mixin.rb
database_cleaner-1.5.3 lib/database_cleaner/mongo2/truncation_mixin.rb
database_cleaner-1.5.2 lib/database_cleaner/mongo2/truncation_mixin.rb