Sha256: 4769d86f768e78b61308911a7b70e41aeb1e5446398f583c28b8a57bb011876e

Contents?: true

Size: 747 Bytes

Versions: 13

Compression:

Stored size: 747 Bytes

Contents

class MongoDatabaseCleaner
  def self.clean
    root = Rails.root
    
    Dir["#{root}/app/models/**/*.*"].each do |name|
      path_name = name.gsub("#{root}/app/models/", '')
      path_name = path_name.split('/')
      
      next if path_name.try(:first) == 'concerns'
      
      klass = path_name.pop.sub(/\.rb$/,'').camelize
      
      unless path_name.none?
        klass = [path_name.map(&:camelize).join('::'), klass].join('::')
      end
      
      begin
        klass = klass.constantize
      rescue Exception => e
        raise e
        raise [klass, root, name, path_name].inspect
      end
      
      next if klass.respond_to?(:table_name) || !klass.respond_to?(:delete_all)
      
      klass.delete_all
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
voluntary-0.7.1 lib/generators/voluntary/install/templates/spec/support/mongo_database_cleaner.rb
voluntary-0.7.0 lib/generators/voluntary/install/templates/spec/support/mongo_database_cleaner.rb
voluntary-0.6.0 lib/generators/voluntary/install/templates/spec/support/mongo_database_cleaner.rb
voluntary-0.5.2 lib/generators/voluntary/install/templates/spec/support/mongo_database_cleaner.rb
voluntary-0.5.1 lib/generators/voluntary/install/templates/spec/support/mongo_database_cleaner.rb
voluntary-0.5.0 lib/generators/voluntary/install/templates/spec/support/mongo_database_cleaner.rb
voluntary-0.4.0 lib/generators/voluntary/install/templates/spec/support/mongo_database_cleaner.rb
voluntary-0.3.0 lib/generators/voluntary/install/templates/spec/support/mongo_database_cleaner.rb
voluntary-0.2.4 lib/generators/voluntary/install/templates/spec/support/mongo_database_cleaner.rb
voluntary-0.2.3 lib/generators/voluntary/install/templates/spec/support/mongo_database_cleaner.rb
voluntary-0.2.2 lib/generators/voluntary/install/templates/spec/support/mongo_database_cleaner.rb
voluntary-0.2.1 lib/generators/voluntary/install/templates/spec/support/mongo_database_cleaner.rb
voluntary-0.2.0 lib/generators/voluntary/install/templates/spec/support/mongo_database_cleaner.rb