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
4 5 6 |
# File 'lib/crm/helpers/persistence.rb', line 4 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#destroy ⇒ Object
45 46 47 48 |
# File 'lib/crm/helpers/persistence.rb', line 45 def destroy crm_object.destroy self end |
#persist ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/crm/helpers/persistence.rb', line 50 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
23 24 25 |
# File 'lib/crm/helpers/persistence.rb', line 23 def save update end |
#save! ⇒ Object
27 28 29 |
# File 'lib/crm/helpers/persistence.rb', line 27 def save! update! end |
#update(attributes = {}) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/crm/helpers/persistence.rb', line 31 def update(attributes = {}) assign_crm_attributes(attributes) return false if invalid? persist end |
#update!(attributes = {}) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/crm/helpers/persistence.rb', line 38 def update!(attributes = {}) assign_crm_attributes(attributes) raise Crm::Errors::InvalidValues.new('', self.errors) if invalid? persist end |