Module: SmoothOperator::Persistence
- Included in:
- Base
- Defined in:
- lib/smooth_operator/persistence.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#last_remote_call ⇒ Object
readonly
Returns the value of attribute last_remote_call.
Class Method Summary collapse
Instance Method Summary collapse
- #destroy(relative_path = nil, data = {}, options = {}) ⇒ Object
- #destroyed? ⇒ Boolean
- #get_primary_key ⇒ Object
- #marked_for_destruction?(bypass_cache = false) ⇒ Boolean
- #new_record?(bypass_cache = false) ⇒ Boolean
- #persisted? ⇒ Boolean
- #reload(relative_path = nil, data = {}, options = {}) ⇒ Object
- #save(relative_path = nil, data = {}, options = {}) ⇒ Object
- #save!(relative_path = nil, data = {}, options = {}) ⇒ Object
Instance Attribute Details
#last_remote_call ⇒ Object (readonly)
Returns the value of attribute last_remote_call.
8 9 10 |
# File 'lib/smooth_operator/persistence.rb', line 8 def last_remote_call @last_remote_call end |
Class Method Details
.included(base) ⇒ Object
4 5 6 |
# File 'lib/smooth_operator/persistence.rb', line 4 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#destroy(relative_path = nil, data = {}, options = {}) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/smooth_operator/persistence.rb', line 60 def destroy(relative_path = nil, data = {}, = {}) return false unless persisted? persistence_call(:destroy, relative_path, data, ) do |remote_call| @destroyed = true if remote_call.status block_given? ? yield(remote_call) : remote_call.status end end |
#destroyed? ⇒ Boolean
34 35 36 37 38 |
# File 'lib/smooth_operator/persistence.rb', line 34 def destroyed? return @destroyed if defined?(@destroyed) @destroyed = false end |
#get_primary_key ⇒ Object
10 11 12 |
# File 'lib/smooth_operator/persistence.rb', line 10 def get_primary_key get_internal_data(self.class.primary_key) end |
#marked_for_destruction?(bypass_cache = false) ⇒ Boolean
28 29 30 31 32 |
# File 'lib/smooth_operator/persistence.rb', line 28 def marked_for_destruction?(bypass_cache = false) return @marked_for_destruction if !bypass_cache && defined?(@marked_for_destruction) @marked_for_destruction = ["true", "1", true].include?(get_internal_data(self.class.destroy_key)) end |
#new_record?(bypass_cache = false) ⇒ Boolean
22 23 24 25 26 |
# File 'lib/smooth_operator/persistence.rb', line 22 def new_record?(bypass_cache = false) return @new_record if !bypass_cache && defined?(@new_record) @new_record = Helpers.blank?(get_primary_key) end |
#persisted? ⇒ Boolean
40 41 42 |
# File 'lib/smooth_operator/persistence.rb', line 40 def persisted? !(new_record? || destroyed?) end |
#reload(relative_path = nil, data = {}, options = {}) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/smooth_operator/persistence.rb', line 14 def reload(relative_path = nil, data = {}, = {}) raise 'UnknownPath' if Helpers.blank?(relative_path) && (!respond_to?(self.class.primary_key) || Helpers.blank?(get_primary_key)) persistence_call(:reload, relative_path, data, ) do |remote_call| block_given? ? yield(remote_call) : remote_call.status end end |
#save(relative_path = nil, data = {}, options = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/smooth_operator/persistence.rb', line 44 def save(relative_path = nil, data = {}, = {}) data = data_with_object_attributes(data, ) if new_record? create(relative_path, data, ) { |remote_call| block_given? ? yield(remote_call) : remote_call.status } else update(relative_path, data, ) { |remote_call| block_given? ? yield(remote_call) : remote_call.status } end end |
#save!(relative_path = nil, data = {}, options = {}) ⇒ Object
54 55 56 57 58 |
# File 'lib/smooth_operator/persistence.rb', line 54 def save!(relative_path = nil, data = {}, = {}) save(relative_path, data, ) do |remote_call| block_given? ? yield(remote_call) : remote_call.status end || raise('RecordNotSaved') end |