Skip to content

Instantly share code, notes, and snippets.

@josefrichter
Created June 24, 2010 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josefrichter/451417 to your computer and use it in GitHub Desktop.
Save josefrichter/451417 to your computer and use it in GitHub Desktop.
# 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