Class: DatabasusRuby::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/databasus_ruby/record.rb,
sig/databasus_ruby.rbs

Overview

A payload that remembers the client it came from, so the record can reach the endpoints related to it:

client.databases.get(id).backups(status: "COMPLETED")

Plain Object stays the wrapper for nested fields and for responses that have nothing hanging off them; Record exists only for the payloads whose domain has related endpoints.

Direct Known Subclasses

Database

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Object

#==, #[], #hash, #inspect, #key?, #keys, #method_missing, #respond_to_missing?, #to_h

Constructor Details

#initialize(client, attributes = {}) ⇒ Record

Returns a new instance of Record.

Parameters:

  • client (Client)
  • attributes (payload) (defaults to: {})


15
16
17
18
# File 'lib/databasus_ruby/record.rb', line 15

def initialize(client, attributes = {})
  @client = client
  super(attributes)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class DatabasusRuby::Object

Instance Attribute Details

#clientClient (readonly)

Returns the value of attribute client.

Returns:



13
14
15
# File 'lib/databasus_ruby/record.rb', line 13

def client
  @client
end

Instance Method Details

#id!String

Related endpoints address the record by id, and the API omits empty fields, so a record built from a partial payload has to say so rather than sending a request with a nil id.

Returns:

  • (String)

Raises:



25
26
27
28
29
30
# File 'lib/databasus_ruby/record.rb', line 25

def id!
  value = self["id"]
  raise Error, "this #{self.class.name} has no id" if value.nil? || value.to_s.empty?

  value
end