Class: Zizq::Resources::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/zizq/resources/resource.rb

Overview

Base class for all typed response wrappers. Holds a reference to the Client (for following links) and the raw response hash.

Direct Known Subclasses

ErrorRecord, Job, Page

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, data) ⇒ Resource

Returns a new instance of Resource.



18
19
20
21
# File 'lib/zizq/resources/resource.rb', line 18

def initialize(client, data)
  @client = client
  @data = data
end

Instance Attribute Details

#clientObject (readonly)

Returns the client instance that returned this resource.



13
14
15
# File 'lib/zizq/resources/resource.rb', line 13

def client
  @client
end

Instance Method Details

#inspectObject

Omit the client from inspect output to reduce noise.



29
30
31
32
33
34
35
# File 'lib/zizq/resources/resource.rb', line 29

def inspect #: () -> String
  ivars = instance_variables
    .reject { |v| v == :@client }
    .map { |v| " #{v}=#{instance_variable_get(v).inspect}" }
    .join
  "#<#{self.class}#{ivars}>"
end

#to_hObject

Returns the underlying raw response hash.



24
25
26
# File 'lib/zizq/resources/resource.rb', line 24

def to_h #: () -> Hash[String, untyped]
  @data
end