Permalink
Browse files

Add a truncate! convenience method

  • Loading branch information...
1 parent af0c87a commit 9aa7e2975877dff848c026449c243d195ccea436 @durran durran committed Sep 20, 2012
Showing with 18 additions and 0 deletions.
  1. +18 −0 lib/mongoid/config.rb
View
@@ -120,6 +120,8 @@ def override_session(name)
# @example Purge all data.
# Mongoid::Config.purge!
#
+ # @note This is the fastest way to drop all data.
+ #
# @return [ true ] true.
#
# @since 2.0.2
@@ -129,6 +131,22 @@ def purge!
end and true
end
+ # Truncate all data in all collections, but not the indexes.
+ #
+ # @example Truncate all collection data.
+ # Mongoid::Config.truncate!
+ #
+ # @note This will be slower than purge!
+ #
+ # @return [ true ] true.
+ #
+ # @since 2.0.2
+ def truncate!
+ Sessions.default.collections.each do |collection|
+ collection.find.remove_all
+ end and true
+ end
+
# Set the configuration options. Will validate each one individually.
#
# @example Set the options.

0 comments on commit 9aa7e29

Please sign in to comment.