Class: Zizq::Resources::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/zizq/resources/resource.rb,
sig/generated/zizq/resources/resource.rbs

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

CronEntry, CronGroup, ErrorRecord, JobTemplate, Page

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, data) ⇒ Resource

Returns a new instance of Resource.

Parameters:



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

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

Instance Attribute Details

#clientClient (readonly)

Returns the client instance that returned this resource.

Returns:



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.

Returns:

  • (Object)


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

#ms_to_seconds(value) ⇒ Object

Convert a millisecond timestamp to fractional seconds, nil-safe.

Parameters:

  • value (Object)

Returns:

  • (Object)


40
41
42
# File 'lib/zizq/resources/resource.rb', line 40

def ms_to_seconds(value) #: (Integer?) -> Float?
  value&./(1000.0)
end

#to_hObject

Returns the underlying raw response hash.

Returns:

  • (Object)


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

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