mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
Merge pull request #356 from mrb/reduce_method_complexity
Reduce mongoid_collection_names complexity
This commit is contained in:
commit
4a06819db5
2 changed files with 10 additions and 5 deletions
|
@ -7,7 +7,7 @@ Each strategy is a small amount of code but is code that is usually needed in an
|
|||
|
||||
ActiveRecord, DataMapper, Sequel, MongoMapper, Mongoid, CouchPotato, Ohm and Redis are supported.
|
||||
|
||||
[![Build Status](https://travis-ci.org/DatabaseCleaner/database_cleaner.svg?branch=master)](https://travis-ci.org/DatabaseCleaner/database_cleaner)
|
||||
[![Build Status](https://travis-ci.org/DatabaseCleaner/database_cleaner.svg?branch=master)](https://travis-ci.org/DatabaseCleaner/database_cleaner) [![Code Climate](https://codeclimate.com/github/DatabaseCleaner/database_cleaner/badges/gpa.svg)](https://codeclimate.com/github/DatabaseCleaner/database_cleaner)
|
||||
|
||||
Here is an overview of the strategies supported for each library:
|
||||
|
||||
|
|
|
@ -20,10 +20,7 @@ module DatabaseCleaner
|
|||
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
|
||||
(names[klass.db.name] << klass.collection_name) if valid_collection_name?(klass)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -52,6 +49,14 @@ module DatabaseCleaner
|
|||
|
||||
db_collections
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def valid_collection_name?(klass)
|
||||
klass.ancestors.map(&:to_s).include?('Mongoid::Document') &&
|
||||
!klass.embedded &&
|
||||
!klass.collection_name.empty?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue