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
- #last_remote_call ⇒ Object
- #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
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/smooth_operator/persistence.rb', line 56 def destroy(relative_path = nil, data = {}, = {}) return false unless persisted? relative_path = "#{id}" 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 |
# File 'lib/smooth_operator/persistence.rb', line 36 def destroyed? @destroyed || false end |
#last_remote_call ⇒ Object
40 41 42 |
# File 'lib/smooth_operator/persistence.rb', line 40 def last_remote_call @last_remote_call 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
44 45 46 |
# File 'lib/smooth_operator/persistence.rb', line 44 def persisted? !(new_record? || destroyed?) end |
#save(relative_path = nil, data = {}, options = {}) ⇒ Object
48 49 50 |
# File 'lib/smooth_operator/persistence.rb', line 48 def save(relative_path = nil, data = {}, = {}) create_or_update(relative_path, data, ) end |
#save!(relative_path = nil, data = {}, options = {}) ⇒ Object
52 53 54 |
# File 'lib/smooth_operator/persistence.rb', line 52 def save!(relative_path = nil, data = {}, = {}) create_or_update(relative_path, data, ) || raise('RecordNotSaved') end |