Created
June 24, 2010 13:04
-
-
Save josefrichter/451417 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# taken from http://github.com/ianwhite/pickle/blob/master/lib/pickle/adapters/active_record.rb | |
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 | |
::ActiveRecord::Base.__send__(:subclasses).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 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment