Class: Apiwork::Introspection::Param::Object

Inherits:
Base
  • Object
show all
Defined in:
lib/apiwork/introspection/param/object.rb

Overview

Object param representing structured data with named fields.

Examples:

Basic usage

param.type # => :object
param.object? # => true
param.scalar? # => false

Fields

param.shape # => { name: Param, email: Param }

Partial objects (for updates)

param.partial? # => true if all fields are optional

Instance Method Summary collapse

Methods inherited from Base

#array?, #binary?, #boolean?, #boundable?, #concrete?, #date?, #datetime?, #decimal?, #default?, #deprecated?, #description, #enum?, #enum_reference?, #formattable?, #initialize, #integer?, #literal?, #nullable?, #number?, #numeric?, #optional?, #record?, #reference?, #scalar?, #string?, #tag, #time?, #type, #union?, #unknown?, #uuid?

Constructor Details

This class inherits a constructor from Apiwork::Introspection::Param::Base

Instance Method Details

#object?Boolean

Whether this param is an object.

Returns:



42
43
44
# File 'lib/apiwork/introspection/param/object.rb', line 42

def object?
  true
end

#partial?Boolean

Whether this param is partial.

Returns:



34
35
36
# File 'lib/apiwork/introspection/param/object.rb', line 34

def partial?
  @dump[:partial]
end

#shapeHash{Symbol => Param::Base}

The shape for this param.

Returns:



24
25
26
27
28
# File 'lib/apiwork/introspection/param/object.rb', line 24

def shape
  return @shape if defined?(@shape)

  @shape = @dump[:shape]&.transform_values { |dump| Param.build(dump) } || {}
end

#to_hHash

Converts this param to a hash.

Returns:

  • (Hash)


50
51
52
53
54
55
# File 'lib/apiwork/introspection/param/object.rb', line 50

def to_h
  result = super
  result[:partial] = partial?
  result[:shape] = shape.transform_values(&:to_h)
  result
end