class DatabaseCleaner::Mongo::Truncation
Private Instance Methods
collections()
click to toggle source
# File lib/database_cleaner/mongo/truncation.rb, line 41 def collections return collections_cache[database.name] if collections_cache.has_key?(database.name) db_collections = database.collections.select { |c| c.name !~ /^system\./ } missing_collections = mongoid_collection_names[database.name] - db_collections.map(&:name) if missing_collections.empty? collections_cache[database.name] = db_collections else not_caching(database.name, missing_collections) end db_collections end
collections_cache()
click to toggle source
# File lib/database_cleaner/mongo/truncation.rb, line 16 def collections_cache @@collections_cache ||= {} end
database()
click to toggle source
# File lib/database_cleaner/mongo/truncation.rb, line 12 def database db end
mongoid_collection_names()
click to toggle source
# File lib/database_cleaner/mongo/truncation.rb, line 20 def mongoid_collection_names @@mongoid_collection_names ||= Hash.new{|h,k| h[k]=[]}.tap do |names| ObjectSpace.each_object(Class) do |klass| next unless klass.ancestors.map(&:to_s).include?('Mongoid::Document') next if klass.embedded next if klass.collection_name.empty? names[klass.db.name] << klass.collection_name end end end
not_caching(db_name, list)
click to toggle source
# File lib/database_cleaner/mongo/truncation.rb, line 31 def not_caching(db_name, list) @@not_caching ||= {} unless @@not_caching.has_key?(db_name) @@not_caching[db_name] = true puts "Not caching collection names for db #{db_name}. Missing these from models: #{list}" end end