Sha256: d8eeea06b60f10b3f8fba711cf430e06a7b437953b18d2083c6721f743c90744

Contents?: true

Size: 1.13 KB

Versions: 4

Compression:

Stored size: 1.13 KB

Contents

require 'mongoid'

module Mongoid
  module Document
    module PickleAdapter
      include Pickle::Adapter::Base

      # Do not consider these to be part of the class list
      def self.except_classes
        @@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}
      end

      # get a list of column names for a given class
      def self.column_names(klass)
        klass.fields.keys
      end

      # Get an instance by id of the model
      def self.get_model(klass, id)
        klass.find(id)
      end

      # Find the first instance matching conditions
      def self.find_first_model(klass, conditions)
        klass.first(:conditions => conditions)
      end

      # Find all models matching conditions
      def self.find_all_models(klass, conditions)
        klass.all(:conditions => conditions)
      end

      # Create a model with given attributes
      def self.create_model(klass, attributes)
        klass.create!(attributes)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 3 rubygems

Version Path
judit-pickle-0.4.2 lib/pickle/adapters/mongoid.rb
pickle-0.4.3 lib/pickle/adapters/mongoid.rb
pickle-has_many_support-0.4.2 lib/pickle/adapters/mongoid.rb
pickle-0.4.2 lib/pickle/adapters/mongoid.rb