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

.column_names(klass) ⇒ Object

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

.create_model(klass, attributes) ⇒ Object

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

.except_classesObject

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

.find_all_models(klass, conditions) ⇒ Object

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

.find_first_model(klass, conditions) ⇒ Object

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

.get_model(klass, id) ⇒ Object

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

.model_classesObject

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