module SmoothOperator::Persistence

Attributes

last_remote_call[R]

Public Class Methods

included(base) click to toggle source
# File lib/smooth_operator/persistence.rb, line 4
def self.included(base)
  base.extend(ClassMethods)
end

Public Instance Methods

destroy(relative_path = nil, data = {}, options = {}) { |remote_call| ... } click to toggle source
# File lib/smooth_operator/persistence.rb, line 63
def destroy(relative_path = nil, data = {}, options = {})
  return false unless persisted?

  resource_data = resource_data_for_server(data, options)

  make_a_persistence_call(:destroy, relative_path, resource_data, options) do |remote_call|
    @destroyed = true if remote_call.status

    block_given? ? yield(remote_call) : remote_call.status
  end
end
destroyed?() click to toggle source
# File lib/smooth_operator/persistence.rb, line 26
def destroyed?
  return @destroyed if defined?(@destroyed)

  @destroyed = false
end
known_attribute?(attribute) click to toggle source
Calls superclass method
# File lib/smooth_operator/persistence.rb, line 36
def known_attribute?(attribute)
  super ||
  [self.class.primary_key, self.class.destroy_key].include?(attribute.to_s)
end
marked_for_destruction?(ignore_cache = false) click to toggle source
# File lib/smooth_operator/persistence.rb, line 16
def marked_for_destruction?(ignore_cache = false)
  if !ignore_cache && defined?(@marked_for_destruction)
    return @marked_for_destruction
  end

  _destroy = internal_data_get(self.class.destroy_key)

  @marked_for_destruction = TypeCasting::TRUE_VALUES.include?(_destroy)
end
new_record?(ignore_cache = false) click to toggle source
# File lib/smooth_operator/persistence.rb, line 10
def new_record?(ignore_cache = false)
  return @new_record if !ignore_cache && defined?(@new_record)

  @new_record = Helpers.has_primary_key?(self)
end
persisted?() click to toggle source
# File lib/smooth_operator/persistence.rb, line 32
def persisted?
  !(new_record? || destroyed?)
end
reload(relative_path = nil, data = {}, options = {}) { |remote_call| ... } click to toggle source
# File lib/smooth_operator/persistence.rb, line 41
def reload(relative_path = nil, data = {}, options = {})
  if Helpers.blank?(relative_path) && Helpers.has_primary_key?(self)
    raise 'UnknownPath'
  end

  make_a_persistence_call(:reload, relative_path, data, options) do |remote_call|
    block_given? ? yield(remote_call) : remote_call.status
  end
end
save(relative_path = nil, data = {}, options = {}) { |remote_call| ... } click to toggle source
# File lib/smooth_operator/persistence.rb, line 51
def save(relative_path = nil, data = {}, options = {})
  resource_data = resource_data_for_server(data, options)

  method = new_record? ? :create : :update

  make_a_persistence_call(method, relative_path, resource_data, options) do |remote_call|
    @new_record = false if method == :create && remote_call.status

    block_given? ? yield(remote_call) : remote_call.status
  end
end
save!(relative_path = nil, data = {}, options = {}) { |remote_call| ... } click to toggle source
# File lib/smooth_operator/persistence.rb, line 75
def save!(relative_path = nil, data = {}, options = {})
  save(relative_path, data, options) do |remote_call|
    block_given? ? yield(remote_call) : remote_call.status
  end || raise('RecordNotSaved')
end