Class: GcalMapper::Mapper::ActiveRecord::ActiveRecord
- Inherits:
-
Object
- Object
- GcalMapper::Mapper::ActiveRecord::ActiveRecord
- Defined in:
- lib/gcal_mapper/mapper/active_record.rb
Overview
Adapter for ActiveRecord
Instance Method Summary collapse
-
#create!(attributes) ⇒ Object
create and save object using attributes.
-
#delete!(id) ⇒ Object
delet an object.
-
#find_all ⇒ Array
Find all models.
-
#find_by(field, value) ⇒ Object
find an object from a field and a value.
-
#initialize(base) ⇒ ActiveRecord
constructor
A new instance of ActiveRecord.
-
#update!(id, attributes) ⇒ Object
update an object.
Constructor Details
#initialize(base) ⇒ ActiveRecord
Returns a new instance of ActiveRecord.
24 25 26 |
# File 'lib/gcal_mapper/mapper/active_record.rb', line 24 def initialize(base) @base = base end |
Instance Method Details
#create!(attributes) ⇒ Object
create and save object using attributes
return [Object] createrd object
32 33 34 |
# File 'lib/gcal_mapper/mapper/active_record.rb', line 32 def create!(attributes) @base.create(attributes) end |
#delete!(id) ⇒ Object
delet an object
50 51 52 53 |
# File 'lib/gcal_mapper/mapper/active_record.rb', line 50 def delete!(id) obj = @base.find(id) obj.destroy end |
#find_all ⇒ Array
Find all models
58 59 60 |
# File 'lib/gcal_mapper/mapper/active_record.rb', line 58 def find_all @base.all end |
#find_by(field, value) ⇒ Object
find an object from a field and a value
67 68 69 |
# File 'lib/gcal_mapper/mapper/active_record.rb', line 67 def find_by(field, value) @base.send('find_by_' + field, value) end |
#update!(id, attributes) ⇒ Object
update an object
41 42 43 44 |
# File 'lib/gcal_mapper/mapper/active_record.rb', line 41 def update!(id, attributes) obj = @base.find(id) obj.update_attributes!(attributes) end |