Module: Kalimba::Persistence Abstract
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/kalimba/persistence.rb
Overview
Backend implementations should override all methods that delegate processing to their parent class (invoking “super”).
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.backend ⇒ Module
Module of the persistence backend.
- .logger ⇒ Object
-
.repository(options = {}) ⇒ Any
Create an instance of the backend storage (repository).
Instance Method Summary collapse
-
#destroy ⇒ Boolean
Remove the resource from the backend storage.
-
#destroyed? ⇒ Boolean
Check whether the model has been destroyed (remove from the storage).
- #id ⇒ Object
- #logger ⇒ Object
-
#new_record? ⇒ Boolean
Check whether the model has never been persisted.
-
#persisted? ⇒ Boolean
Check whether the model has ever been persisted.
-
#reload ⇒ self
Retrieve model attributes from the backend storage.
-
#save(options = {}) ⇒ Boolean
Persist the model into the backend storage.
-
#update_attributes(params = {}) ⇒ Boolean
Assign attributes from the given hash and persist the model.
Class Method Details
.backend ⇒ Module
Module of the persistence backend
23 24 25 |
# File 'lib/kalimba/persistence.rb', line 23 def backend self end |
.logger ⇒ Object
27 28 29 |
# File 'lib/kalimba/persistence.rb', line 27 def logger @logger ||= defined?(::Rails) && ::Rails.logger end |
.repository(options = {}) ⇒ Any
Create an instance of the backend storage (repository)
16 17 18 |
# File 'lib/kalimba/persistence.rb', line 16 def repository( = {}) raise NotImplementedError end |
Instance Method Details
#destroy ⇒ Boolean
Remove the resource from the backend storage
128 129 130 131 |
# File 'lib/kalimba/persistence.rb', line 128 def destroy @destroyed = true freeze end |
#destroyed? ⇒ Boolean
Check whether the model has been destroyed (remove from the storage)
114 115 116 |
# File 'lib/kalimba/persistence.rb', line 114 def destroyed? @destroyed end |
#id ⇒ Object
92 93 94 |
# File 'lib/kalimba/persistence.rb', line 92 def id subject && subject.fragment end |
#logger ⇒ Object
152 153 154 |
# File 'lib/kalimba/persistence.rb', line 152 def logger self.class.logger end |
#new_record? ⇒ Boolean
Check whether the model has never been persisted
99 100 101 |
# File 'lib/kalimba/persistence.rb', line 99 def new_record? raise NotImplementedError end |
#persisted? ⇒ Boolean
Check whether the model has ever been persisted
106 107 108 |
# File 'lib/kalimba/persistence.rb', line 106 def persisted? raise NotImplementedError end |
#reload ⇒ self
Retrieve model attributes from the backend storage
121 122 123 |
# File 'lib/kalimba/persistence.rb', line 121 def reload raise NotImplementedError end |
#save(options = {}) ⇒ Boolean
Persist the model into the backend storage
146 147 148 149 150 |
# File 'lib/kalimba/persistence.rb', line 146 def save( = {}) @previously_changed = changes @changed_attributes.clear true end |
#update_attributes(params = {}) ⇒ Boolean
Assign attributes from the given hash and persist the model
137 138 139 140 |
# File 'lib/kalimba/persistence.rb', line 137 def update_attributes(params = {}) assign_attributes(params) save end |