Permalink
Browse files

Added :all and :except options to truncate_tables

Signed-off-by: Sevenwire <git@sevenwire.com>
  • Loading branch information...
1 parent 92931d9 commit 67e4623779348c66022ef81c546a4560c299182e @viking viking committed with Sevenwire May 22, 2009
Showing with 10 additions and 0 deletions.
  1. +10 −0 lib/bootstrapper.rb
View
@@ -13,6 +13,16 @@ def self.run(key)
end
def self.truncate_tables(*tables)
+ options = tables.last.is_a?(Hash) ? tables.pop : {}
+ if tables == [:all]
+ except = options[:except] || []
+ except = except.is_a?(Array) ? except.collect { |x| x.to_s } : [except.to_s]
+
+ tables = ActiveRecord::Base.connection.tables.select do |table|
+ table !~ /schema_(info|migrations)/ && !except.include?(table)
+ end
+ end
+
tables.each do |table|
ActiveRecord::Base.connection.truncate_table(table)
end

0 comments on commit 67e4623

Please sign in to comment.