Module: ActiveRecord::Base::PickleAdapter

Includes:
Pickle::Adapter::Base
Defined in:
lib/pickle/adapters/active_record.rb

Class Method Summary (collapse)

Methods included from Pickle::Adapter::Base

adapters, included

Class Method Details

+ (Object) column_names(klass)

get a list of column names for a given class



33
34
35
# File 'lib/pickle/adapters/active_record.rb', line 33

def self.column_names(klass)
  klass.column_names
end

+ (Object) create_model(klass, attributes)

Create a model using attributes



53
54
55
# File 'lib/pickle/adapters/active_record.rb', line 53

def self.create_model(klass, attributes)
  klass.create!(attributes)
end

+ (Object) except_classes

Do not consider these to be part of the class list



12
13
14
15
16
17
# File 'lib/pickle/adapters/active_record.rb', line 12

def self.except_classes
  @@except_classes ||= [
    "CGI::Session::ActiveRecordStore::Session",
    "ActiveRecord::SessionStore::Session"
  ]
end

+ (Object) find_all_models(klass, conditions)

Find all models matching conditions



48
49
50
# File 'lib/pickle/adapters/active_record.rb', line 48

def self.find_all_models(klass, conditions)
  klass.find(:all, :conditions => conditions)
end

+ (Object) find_first_model(klass, conditions)

Find the first instance matching conditions



43
44
45
# File 'lib/pickle/adapters/active_record.rb', line 43

def self.find_first_model(klass, conditions)
  klass.find(:first, :conditions => conditions)
end

+ (Object) get_model(klass, id)

Get an instance by id of the model



38
39
40
# File 'lib/pickle/adapters/active_record.rb', line 38

def self.get_model(klass, id)
  klass.find(id)
end

+ (Object) model_classes

Gets a list of the available models for this adapter



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pickle/adapters/active_record.rb', line 20

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