class DatabaseCleaner::Mongo::Deletion

Public Class Methods

new(only: [], except: [], cache_tables: nil) click to toggle source
# File lib/database_cleaner/mongo/deletion.rb, line 8
def initialize only: [], except: [], cache_tables: nil
  @only = only
  @except = except
  if !cache_tables.nil?
    DatabaseCleaner.deprecate "The mongo adapter's :cache_tables option has no effect, and will be removed in database_cleaner-mongo 3.0."
  end
end

Public Instance Methods

clean() click to toggle source
# File lib/database_cleaner/mongo/deletion.rb, line 20
def clean
  collections_to_delete.each(&:delete_many)
end
db() click to toggle source
# File lib/database_cleaner/mongo/deletion.rb, line 16
def db
  @db || raise("You have not specified a database.  (see Mongo::Database)")
end

Private Instance Methods

collections() click to toggle source
# File lib/database_cleaner/mongo/deletion.rb, line 32
def collections
  db.collections.select { |c| c.name !~ /^system\./ }
end
collections_to_delete() click to toggle source
# File lib/database_cleaner/mongo/deletion.rb, line 26
def collections_to_delete
  collections.select do |c|
    (@only.none? || @only.include?(c.name)) && !@except.include?(c.name)
  end
end