lib/pickle/adapters/mongoid.rb in pickle-0.5.0 vs lib/pickle/adapters/mongoid.rb in pickle-0.5.1

- old
+ new

@@ -10,11 +10,13 @@ @@except_classes ||= [] end # Gets a list of the available models for this adapter def self.model_classes - ObjectSpace.each_object(Class).to_a.select {|klass| klass.ancestors.include? Mongoid::Document} + ObjectSpace.each_object(Class).to_a.select do |klass| + klass.name && klass.ancestors.include?(Mongoid::Document) + end end # get a list of column names for a given class def self.column_names(klass) klass.try(:fields).try(:keys) || [] @@ -25,15 +27,23 @@ klass.find(id) end # Find the first instance matching conditions def self.find_first_model(klass, conditions) - klass.first(:conditions => conditions) + if defined? ::Mongoid::Criteria + klass.where(conditions).first + else + klass.first(:conditions => conditions) + end end # Find all models matching conditions def self.find_all_models(klass, conditions) - klass.all(:conditions => conditions) + if defined? ::Mongoid::Criteria + klass.where(conditions).to_a + else + klass.all(:conditions => conditions) + end end # Create a model with given attributes def self.create_model(klass, attributes) klass.create!(attributes)