Module: SmoothOperator::Persistence
- Included in:
- Base
- Defined in:
- lib/smooth_operator/persistence.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#extra_params ⇒ Object
Returns the value of attribute extra_params.
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
Instance Attribute Details
#extra_params ⇒ Object
Returns the value of attribute extra_params.
30 31 32 |
# File 'lib/smooth_operator/persistence.rb', line 30 def extra_params @extra_params end |
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 67 68 69 70 |
# File 'lib/smooth_operator/persistence.rb', line 56 def destroy(relative_path = nil, data = {}, = {}) return false unless persisted? relative_path = id.to_s if Helpers.blank?(relative_path) success = {} success = make_remote_call(self.class.methods_http_verbs[:destroy], relative_path, data, ) do |remote_call| success = remote_call.status @destroyed = true if success end success end |
#destroyed? ⇒ Boolean
38 39 40 41 42 |
# File 'lib/smooth_operator/persistence.rb', line 38 def destroyed? return @destroyed if defined?(@destroyed) @destroyed = false end |
#new_record? ⇒ Boolean
32 33 34 35 36 |
# File 'lib/smooth_operator/persistence.rb', line 32 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 |