Module: DataMapper::Support::ActiveRecordImpersonation::ClassMethods

Defined in:
lib/data_mapper/support/active_record_impersonation.rb

Instance Method Summary collapse

Instance Method Details

#[](id_or_hash) ⇒ Object



60
61
62
# File 'lib/data_mapper/support/active_record_impersonation.rb', line 60

def [](id_or_hash)
  first(id_or_hash)
end

#all(options = {}, &b) ⇒ Object



32
33
34
# File 'lib/data_mapper/support/active_record_impersonation.rb', line 32

def all(options = {}, &b)
  database.all(self, options, &b)
end

#create(attributes) ⇒ Object



64
65
66
67
68
# File 'lib/data_mapper/support/active_record_impersonation.rb', line 64

def create(attributes)
  instance = self.new(attributes)
  instance.save
  instance
end

#delete_allObject



40
41
42
# File 'lib/data_mapper/support/active_record_impersonation.rb', line 40

def delete_all
  database.delete_all(self)
end

#find(type_or_id, options = {}, &b) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/data_mapper/support/active_record_impersonation.rb', line 48

def find(type_or_id, options = {}, &b)
  case type_or_id
    when :first then first(options, &b)
    when :all then all(options, &b)
    else first(type_or_id, options, &b)
  end
end

#find_by_sql(*args) ⇒ Object



56
57
58
# File 'lib/data_mapper/support/active_record_impersonation.rb', line 56

def find_by_sql(*args)
  DataMapper::database.query(*args)
end

#find_or_create(search_attributes, create_attributes = nil) ⇒ Object



28
29
30
# File 'lib/data_mapper/support/active_record_impersonation.rb', line 28

def find_or_create(search_attributes, create_attributes = nil)
  first(search_attributes) || create(search_attributes.merge(create_attributes))
end

#first(*args, &b) ⇒ Object



36
37
38
# File 'lib/data_mapper/support/active_record_impersonation.rb', line 36

def first(*args, &b)
  database.first(self, *args, &b)
end

#truncate!Object



44
45
46
# File 'lib/data_mapper/support/active_record_impersonation.rb', line 44

def truncate!
  database.truncate(self)
end