Class: Apiwork::Introspection::Type
- Inherits:
-
Object
- Object
- Apiwork::Introspection::Type
- Defined in:
- lib/apiwork/introspection/type.rb
Overview
Wraps custom type definitions.
Types can be objects (with shapes) or unions (with variants).
Instance Method Summary collapse
-
#deprecated? ⇒ Boolean
Whether this type is deprecated.
-
#description ⇒ String?
The description for this type.
-
#discriminator ⇒ Symbol?
The discriminator for this type.
-
#example ⇒ Object?
The example for this type.
-
#extends ⇒ Array<Symbol>
The extends for this type.
-
#extends? ⇒ Boolean
Whether this type extends other types.
-
#initialize(dump) ⇒ Type
constructor
A new instance of Type.
-
#object? ⇒ Boolean
Whether this type is an object.
-
#scope ⇒ String?
The scope for this type.
-
#shape ⇒ Hash{Symbol => Param}
The shape for this type.
-
#to_h ⇒ Hash
Converts this type to a hash.
-
#type ⇒ Symbol?
The type for this type.
-
#union? ⇒ Boolean
Whether this type is a union.
-
#variants ⇒ Array<Param>
The variants for this type.
Constructor Details
#initialize(dump) ⇒ Type
Returns a new instance of Type.
19 20 21 |
# File 'lib/apiwork/introspection/type.rb', line 19 def initialize(dump) @dump = dump end |
Instance Method Details
#deprecated? ⇒ Boolean
Whether this type is deprecated.
115 116 117 |
# File 'lib/apiwork/introspection/type.rb', line 115 def deprecated? @dump[:deprecated] end |
#description ⇒ String?
The description for this type.
75 76 77 |
# File 'lib/apiwork/introspection/type.rb', line 75 def description @dump[:description] end |
#discriminator ⇒ Symbol?
The discriminator for this type.
67 68 69 |
# File 'lib/apiwork/introspection/type.rb', line 67 def discriminator @dump[:discriminator] end |
#example ⇒ Object?
The example for this type.
99 100 101 |
# File 'lib/apiwork/introspection/type.rb', line 99 def example @dump[:example] end |
#extends ⇒ Array<Symbol>
The extends for this type.
83 84 85 |
# File 'lib/apiwork/introspection/type.rb', line 83 def extends @dump[:extends] end |
#extends? ⇒ Boolean
Whether this type extends other types.
91 92 93 |
# File 'lib/apiwork/introspection/type.rb', line 91 def extends? extends.any? end |
#object? ⇒ Boolean
Whether this type is an object.
35 36 37 |
# File 'lib/apiwork/introspection/type.rb', line 35 def object? type == :object end |
#scope ⇒ String?
The scope for this type.
107 108 109 |
# File 'lib/apiwork/introspection/type.rb', line 107 def scope @dump[:scope] end |
#shape ⇒ Hash{Symbol => Param}
The shape for this type.
51 52 53 |
# File 'lib/apiwork/introspection/type.rb', line 51 def shape @shape ||= @dump[:shape].transform_values { |dump| Param.build(dump) } end |
#to_h ⇒ Hash
Converts this type to a hash.
123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/apiwork/introspection/type.rb', line 123 def to_h { deprecated: deprecated?, description: description, discriminator: discriminator, example: example, extends: extends, scope: scope, shape: shape.transform_values(&:to_h), type: type, variants: variants.map(&:to_h), } end |
#type ⇒ Symbol?
The type for this type.
27 28 29 |
# File 'lib/apiwork/introspection/type.rb', line 27 def type @dump[:type] end |
#union? ⇒ Boolean
Whether this type is a union.
43 44 45 |
# File 'lib/apiwork/introspection/type.rb', line 43 def union? type == :union end |