Module: Crm::Helpers::Persistence
- Defined in:
- lib/crm/helpers/persistence.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #destroy ⇒ Object
- #persist ⇒ Object
- #save ⇒ Object
- #save! ⇒ Object
- #update(attributes = {}) ⇒ Object
- #update!(attributes = {}) ⇒ Object
Class Method Details
.included(base) ⇒ Object
6 7 8 |
# File 'lib/crm/helpers/persistence.rb', line 6 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#destroy ⇒ Object
50 51 52 53 |
# File 'lib/crm/helpers/persistence.rb', line 50 def destroy crm_object.destroy self end |
#persist ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/crm/helpers/persistence.rb', line 55 def persist return false if invalid? @crm_object = if crm_object.nil? self.class.crm_class.create(crm_attributes) else crm_object.update(crm_attributes) end assign_crm_attributes(crm_object.attributes) true end |
#save ⇒ Object
28 29 30 |
# File 'lib/crm/helpers/persistence.rb', line 28 def save update end |
#save! ⇒ Object
32 33 34 |
# File 'lib/crm/helpers/persistence.rb', line 32 def save! update! end |
#update(attributes = {}) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/crm/helpers/persistence.rb', line 36 def update(attributes = {}) assign_crm_attributes(attributes) return false if invalid? persist end |
#update!(attributes = {}) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/crm/helpers/persistence.rb', line 43 def update!(attributes = {}) assign_crm_attributes(attributes) raise Crm::Errors::InvalidValues.new('', errors) if invalid? persist end |