Sha256: dce88e05f20a5b6c77535871004e169cf2d68495f67ad949e7c4d3c2906d05d4

Contents?: true

Size: 684 Bytes

Versions: 4

Compression:

Stored size: 684 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!
    raise Restly::Error::MissingId, "Cannot reload #{resource_name}, either it hasn't been created or it is missing an ID." unless new_record?
    set_attributes_from_response connection.get(path_with_format, force: true)
    @loaded = true
    self
  end

  alias :load! :reload!

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
restly-0.0.1.beta.1 lib/restly/base/instance/persistence.rb
restly-0.0.1.alpha.22 lib/restly/base/instance/persistence.rb
restly-0.0.1.alpha.19 lib/restly/base/instance/persistence.rb
restly-0.0.1.alpha.18 lib/restly/base/instance/persistence.rb