Sha256: 6a1091b1c6a2e922ef1d39a5212b956b1f96d0e4c9dd7fe08486f6d719503742

Contents?: true

Size: 1.44 KB

Versions: 15

Compression:

Stored size: 1.44 KB

Contents

begin
  require 'activerecord'
rescue LoadError
  require 'active_record'
end

class ActiveRecord::Base
  module PickleAdapter
    include Pickle::Adapter::Base

    # Do not consider these to be part of the class list
    def self.except_classes
      @@except_classes ||= [
        "CGI::Session::ActiveRecordStore::Session",
        "ActiveRecord::SessionStore::Session"
      ]
    end

    # Gets a list of the available models for this adapter
    def self.model_classes
      begin
        klasses = ::ActiveRecord::Base.__send__(:descendants) # Rails 3
      rescue
        klasses = ::ActiveRecord::Base.__send__(:subclasses) # Rails 2
      end

      klasses.select do |klass|
        !klass.abstract_class? && klass.table_exists? && !except_classes.include?(klass.name)
      end
    end

    # get a list of column names for a given class
    def self.column_names(klass)
      klass.column_names
    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.find(:first, :conditions => conditions)
    end

    # Find all models matching conditions
    def self.find_all_models(klass, conditions)
      klass.find(:all, :conditions => conditions)
    end
    
    # Create a model using attributes
    def self.create_model(klass, attributes)
      klass.create!(attributes)
    end
  end
end

Version data entries

15 entries across 15 versions & 3 rubygems

Version Path
pickle-0.5.0 lib/pickle/adapters/active_record.rb
pickle-0.4.11 lib/pickle/adapters/active_record.rb
pickle-0.4.10 lib/pickle/adapters/active_record.rb
pickle-0.4.9 lib/pickle/adapters/active_record.rb
pickle-0.4.8 lib/pickle/adapters/active_record.rb
pickle-0.4.7 lib/pickle/adapters/active_record.rb
pickle-0.4.6 lib/pickle/adapters/active_record.rb
pickle-0.4.5 lib/pickle/adapters/active_record.rb
pickle-0.4.4 lib/pickle/adapters/active_record.rb
judit-pickle-0.4.2 lib/pickle/adapters/active_record.rb
pickle-0.4.3 lib/pickle/adapters/active_record.rb
pickle-has_many_support-0.4.2 lib/pickle/adapters/active_record.rb
pickle-0.4.2 lib/pickle/adapters/active_record.rb
pickle-0.4.1 lib/pickle/adapters/active_record.rb
pickle-0.4.0 lib/pickle/adapters/active_record.rb