Module: DataMapper::Support::ActiveRecordImpersonation::ClassMethods
- Defined in:
- lib/data_mapper/support/active_record_impersonation.rb
Instance Method Summary collapse
- #[](id_or_hash) ⇒ Object
- #all(options = {}, &b) ⇒ Object
- #create(attributes) ⇒ Object
- #delete_all ⇒ Object
- #find(type_or_id, options = {}, &b) ⇒ Object
- #find_by_sql(*args) ⇒ Object
- #find_or_create(search_attributes, create_attributes = nil) ⇒ Object
- #first(*args, &b) ⇒ Object
- #truncate! ⇒ Object
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( = {}, &b) database.all(self, , &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_all ⇒ Object
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, = {}, &b) case type_or_id when :first then first(, &b) when :all then all(, &b) else first(type_or_id, , &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 |