module Mongoid::Document::PickleAdapter

Public Class Methods

column_names(klass) click to toggle source

get a list of column names for a given class

# File lib/pickle/adapters/mongoid.rb, line 21
def self.column_names(klass)
  klass.try(:fields).try(:keys) || []
end
create_model(klass, attributes) click to toggle source

Create a model with given attributes

# File lib/pickle/adapters/mongoid.rb, line 49
def self.create_model(klass, attributes)
  klass.create!(attributes)
end
except_classes() click to toggle source

Do not consider these to be part of the class list

# File lib/pickle/adapters/mongoid.rb, line 9
def self.except_classes
  @@except_classes ||= []
end
find_all_models(klass, conditions) click to toggle source

Find all models matching conditions

# File lib/pickle/adapters/mongoid.rb, line 40
def self.find_all_models(klass, conditions)
  if defined? ::Mongoid::Criteria
    klass.where(conditions).to_a
  else
    klass.all(:conditions => conditions)
  end
end
find_first_model(klass, conditions) click to toggle source

Find the first instance matching conditions

# File lib/pickle/adapters/mongoid.rb, line 31
def self.find_first_model(klass, conditions)
  if defined? ::Mongoid::Criteria
    klass.where(conditions).first
  else
    klass.first(:conditions => conditions)
  end
end
get_model(klass, id) click to toggle source

Get an instance by id of the model

# File lib/pickle/adapters/mongoid.rb, line 26
def self.get_model(klass, id)
  klass.find(id)
end
model_classes() click to toggle source

Gets a list of the available models for this adapter

# File lib/pickle/adapters/mongoid.rb, line 14
def self.model_classes
  ObjectSpace.each_object(Class).to_a.select do |klass|
    klass.name && klass.ancestors.include?(Mongoid::Document)
  end
end