Sha256: 7bee2360656e3009aabe24a9e87412c4315a24eda75df13aa6df263c467745a7

Contents?: true

Size: 990 Bytes

Versions: 1

Compression:

Stored size: 990 Bytes

Contents

module Restly::Base::Instance::Persistence

  def exists?
    return false unless id

    begin
      @response ||= connection.get(path, force: true)

    rescue OAuth2::Error => e
      @response = e.response

    end

    status = @response.status.to_i
    status < 300 && status >= 200

  end

  def persisted?
    exists? && !changed?
  end

  def new_record?
    !exists?
  end

  def reload!
    return unless initialized? && loaded?
    raise Restly::Error::MissingId, "Cannot reload #{resource_name}, either it hasn't been created or it is missing an ID." unless exists?
    @loaded = true
    set_attributes_from_response connection.get(path_with_format, force: true)
    self
  end

  def load!
    return unless initialized? && loaded?
    raise Restly::Error::MissingId, "Cannot load #{resource_name}, either it hasn't been created or it is missing an ID." unless exists?
    @loaded = true
    set_attributes_from_response connection.get(path_with_format)
    self
  end


end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
restly-0.0.1.beta.3 lib/restly/base/instance/persistence.rb