Module: ActiveRecordExtension
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/active_record_extension.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #delete ⇒ Object
- #destroy ⇒ Object
- #destroy! ⇒ Object
- #save ⇒ Object
- #save! ⇒ Object
- #update(attributes) ⇒ Object
- #update_attribute(name, value) ⇒ Object
Instance Method Details
#delete ⇒ Object
8 9 10 |
# File 'lib/active_record_extension.rb', line 8 def delete ::OData::Model.destroy(self) end |
#destroy ⇒ Object
12 13 14 15 16 |
# File 'lib/active_record_extension.rb', line 12 def destroy destroy! rescue false end |
#destroy! ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/active_record_extension.rb', line 18 def destroy! run_callbacks :destroy do ::OData::Model.destroy(self) end has_errors = errors.present? if has_errors _raise_record_not_destroyed end !has_errors end |
#save ⇒ Object
29 30 31 32 33 |
# File 'lib/active_record_extension.rb', line 29 def save(*) save! rescue false end |
#save! ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/active_record_extension.rb', line 35 def save!(*) validate! run_callbacks :save do ::OData::Model.save(self) end has_errors = errors.present? if has_errors raise_validation_error else reload unless id.nil? end !has_errors end |
#update(attributes) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/active_record_extension.rb', line 49 def update(attributes) attributes.each do |k,v| write_attribute(k,v) end save end |
#update_attribute(name, value) ⇒ Object
56 57 58 59 |
# File 'lib/active_record_extension.rb', line 56 def update_attribute(name, value) write_attribute(name,value) save end |