Class: Apiwork::Introspection::Param::Array

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

Overview

Array param representing ordered collections.

Examples:

Basic usage

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

Element type

param.of # => Param (element type) or nil
param.shape # => {} or { field: Param, ... }

Constraints

param.min # => 1 or nil
param.max # => 10 or nil
param.boundable? # => true

Instance Method Summary collapse

Methods inherited from Base

#binary?, #boolean?, #date?, #datetime?, #decimal?, #default?, #deprecated?, #description, #enum?, #enum_reference?, #formattable?, #initialize, #integer?, #literal?, #nullable?, #number?, #numeric?, #object?, #optional?, #partial?, #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

#array?Boolean

Whether this param is an array.

Returns:



80
81
82
# File 'lib/apiwork/introspection/param/array.rb', line 80

def array?
  true
end

#boundable?Boolean

Whether this param is boundable.

Returns:



96
97
98
# File 'lib/apiwork/introspection/param/array.rb', line 96

def boundable?
  true
end

#concrete?Boolean

Whether this param is concrete.

Returns:



88
89
90
# File 'lib/apiwork/introspection/param/array.rb', line 88

def concrete?
  true
end

#defaultObject?

The default for this param.

Returns ‘nil` for both “no default” and “default is explicitly `nil`”. Use Base#default? to distinguish these cases.

Returns:



30
31
32
# File 'lib/apiwork/introspection/param/array.rb', line 30

def default
  @dump[:default]
end

#exampleObject?

The example for this param.

Returns:



38
39
40
# File 'lib/apiwork/introspection/param/array.rb', line 38

def example
  @dump[:example]
end

#maxInteger?

The maximum for this param.

Returns:



72
73
74
# File 'lib/apiwork/introspection/param/array.rb', line 72

def max
  @dump[:max]
end

#minInteger?

The minimum for this param.

Returns:



64
65
66
# File 'lib/apiwork/introspection/param/array.rb', line 64

def min
  @dump[:min]
end

#ofParam::Base?

The of for this param.

Returns:



46
47
48
# File 'lib/apiwork/introspection/param/array.rb', line 46

def of
  @of ||= @dump[:of] ? Param.build(@dump[:of]) : nil
end

#shapeHash{Symbol => Param::Base}

The shape for this param.

Returns:



54
55
56
57
58
# File 'lib/apiwork/introspection/param/array.rb', line 54

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)


104
105
106
107
108
109
110
111
112
113
# File 'lib/apiwork/introspection/param/array.rb', line 104

def to_h
  result = super
  result[:default] = default
  result[:example] = example
  result[:max] = max
  result[:min] = min
  result[:of] = of&.to_h
  result[:shape] = shape.transform_values(&:to_h)
  result
end