Module: SmoothOperator::Persistence
- Included in:
- Base
- Defined in:
- lib/smooth_operator/persistence.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #destroy(relative_path = nil, data = {}, options = {}) ⇒ Object
- #destroyed? ⇒ Boolean
- #new_record? ⇒ Boolean
- #persisted? ⇒ Boolean
- #save(relative_path = nil, data = {}, options = {}) ⇒ Object
- #save!(relative_path = nil, data = {}, options = {}) ⇒ Object
Class Method Details
.included(base) ⇒ Object
5 6 7 |
# File 'lib/smooth_operator/persistence.rb', line 5 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#destroy(relative_path = nil, data = {}, options = {}) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/smooth_operator/persistence.rb', line 54 def destroy(relative_path = nil, data = {}, = {}) return false unless persisted? relative_path = id.to_s if Helpers.blank?(relative_path) success = make_remote_call(self.class.methods_http_verbs[:destroy], relative_path, data, ) @destroyed = true if success success end |
#destroyed? ⇒ Boolean
36 37 38 39 40 |
# File 'lib/smooth_operator/persistence.rb', line 36 def destroyed? return @destroyed if defined?(@destroyed) @destroyed = false end |
#new_record? ⇒ Boolean
30 31 32 33 34 |
# File 'lib/smooth_operator/persistence.rb', line 30 def new_record? return @new_record if defined?(@new_record) @new_record = Helpers.blank?(get_internal_data("id")) end |
#persisted? ⇒ Boolean
42 43 44 |
# File 'lib/smooth_operator/persistence.rb', line 42 def persisted? !(new_record? || destroyed?) end |
#save(relative_path = nil, data = {}, options = {}) ⇒ Object
46 47 48 |
# File 'lib/smooth_operator/persistence.rb', line 46 def save(relative_path = nil, data = {}, = {}) create_or_update(relative_path, data, ) end |
#save!(relative_path = nil, data = {}, options = {}) ⇒ Object
50 51 52 |
# File 'lib/smooth_operator/persistence.rb', line 50 def save!(relative_path = nil, data = {}, = {}) create_or_update(relative_path, data, ) || raise('RecordNotSaved') end |