Class: Apiwork::Element
- Inherits:
-
Object
- Object
- Apiwork::Element
- Defined in:
- lib/apiwork/element.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#custom_type ⇒ Symbol?
readonly
The custom type name for this element.
-
#discriminator ⇒ Symbol?
readonly
The discriminator for this element.
-
#enum ⇒ Array, ...
readonly
The allowed values for this element.
-
#format ⇒ Symbol?
readonly
The format hint for this element.
-
#inner ⇒ Element?
readonly
The inner element for nested arrays.
-
#max ⇒ Numeric?
readonly
The maximum constraint for this element.
-
#min ⇒ Numeric?
readonly
The minimum constraint for this element.
-
#shape ⇒ Object?
readonly
The shape for this element.
-
#type ⇒ Symbol?
readonly
The type for this element.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#array {|element| ... } ⇒ void
Defines an array.
-
#binary ⇒ void
Defines a binary.
-
#boolean ⇒ void
Defines a boolean.
-
#date ⇒ void
Defines a date.
-
#datetime ⇒ void
Defines a datetime.
-
#decimal(max: nil, min: nil) ⇒ void
Defines a decimal.
-
#initialize ⇒ Element
constructor
A new instance of Element.
-
#integer(enum: nil, max: nil, min: nil) ⇒ void
Defines an integer.
-
#literal(value:) ⇒ void
Defines a literal value.
-
#number(max: nil, min: nil) ⇒ void
Defines a number.
-
#object {|object| ... } ⇒ void
Defines an object.
- #of(type, **options, &block) ⇒ Object
-
#record {|element| ... } ⇒ void
Defines a record.
-
#reference(type_name) ⇒ void
Defines a reference to a named type.
-
#string(enum: nil, format: nil, max: nil, min: nil) ⇒ void
Defines a string.
-
#time ⇒ void
Defines a time.
-
#union(discriminator: nil) {|union| ... } ⇒ void
Defines a union.
-
#unknown ⇒ void
Defines an unknown.
-
#uuid ⇒ void
Defines a UUID.
- #validate! ⇒ Object
Constructor Details
#initialize ⇒ Element
Returns a new instance of Element.
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/apiwork/element.rb', line 66 def initialize @custom_type = nil @defined = false @discriminator = nil @enum = nil @format = nil @inner = nil @max = nil @min = nil @shape = nil @type = nil @value = nil end |
Instance Attribute Details
#custom_type ⇒ Symbol? (readonly)
The custom type name for this element.
55 56 57 |
# File 'lib/apiwork/element.rb', line 55 def custom_type @custom_type end |
#discriminator ⇒ Symbol? (readonly)
The discriminator for this element.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/apiwork/element.rb', line 55 attr_reader :custom_type, :discriminator, :enum, :format, :inner, :max, :min, :shape, :type, :value |
#enum ⇒ Array, ... (readonly)
The allowed values for this element.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/apiwork/element.rb', line 55 attr_reader :custom_type, :discriminator, :enum, :format, :inner, :max, :min, :shape, :type, :value |
#format ⇒ Symbol? (readonly)
The format hint for this element.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/apiwork/element.rb', line 55 attr_reader :custom_type, :discriminator, :enum, :format, :inner, :max, :min, :shape, :type, :value |
#inner ⇒ Element? (readonly)
The inner element for nested arrays.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/apiwork/element.rb', line 55 attr_reader :custom_type, :discriminator, :enum, :format, :inner, :max, :min, :shape, :type, :value |
#max ⇒ Numeric? (readonly)
The maximum constraint for this element.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/apiwork/element.rb', line 55 attr_reader :custom_type, :discriminator, :enum, :format, :inner, :max, :min, :shape, :type, :value |
#min ⇒ Numeric? (readonly)
The minimum constraint for this element.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/apiwork/element.rb', line 55 attr_reader :custom_type, :discriminator, :enum, :format, :inner, :max, :min, :shape, :type, :value |
#shape ⇒ Object? (readonly)
The shape for this element.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/apiwork/element.rb', line 55 attr_reader :custom_type, :discriminator, :enum, :format, :inner, :max, :min, :shape, :type, :value |
#type ⇒ Symbol? (readonly)
The type for this element.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/apiwork/element.rb', line 55 attr_reader :custom_type, :discriminator, :enum, :format, :inner, :max, :min, :shape, :type, :value |
#value ⇒ Object (readonly)
Returns the value of attribute value.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/apiwork/element.rb', line 55 attr_reader :custom_type, :discriminator, :enum, :format, :inner, :max, :min, :shape, :type, :value |
Instance Method Details
#array {|element| ... } ⇒ void
This method returns an undefined value.
Defines an array.
312 313 314 |
# File 'lib/apiwork/element.rb', line 312 def array(&block) of(:array, &block) end |
#binary ⇒ void
This method returns an undefined value.
Defines a binary.
249 250 251 |
# File 'lib/apiwork/element.rb', line 249 def binary of(:binary) end |
#boolean ⇒ void
This method returns an undefined value.
Defines a boolean.
184 185 186 |
# File 'lib/apiwork/element.rb', line 184 def boolean of(:boolean) end |
#date ⇒ void
This method returns an undefined value.
Defines a date.
210 211 212 |
# File 'lib/apiwork/element.rb', line 210 def date of(:date) end |
#datetime ⇒ void
This method returns an undefined value.
Defines a datetime.
197 198 199 |
# File 'lib/apiwork/element.rb', line 197 def datetime of(:datetime) end |
#decimal(max: nil, min: nil) ⇒ void
This method returns an undefined value.
Defines a decimal.
149 150 151 |
# File 'lib/apiwork/element.rb', line 149 def decimal(max: nil, min: nil) of(:decimal, max:, min:) end |
#integer(enum: nil, max: nil, min: nil) ⇒ void
This method returns an undefined value.
Defines an integer.
127 128 129 |
# File 'lib/apiwork/element.rb', line 127 def integer(enum: nil, max: nil, min: nil) of(:integer, enum:, max:, min:) end |
#literal(value:) ⇒ void
This method returns an undefined value.
Defines a literal value.
381 382 383 |
# File 'lib/apiwork/element.rb', line 381 def literal(value:) of(:literal, value:) end |
#number(max: nil, min: nil) ⇒ void
This method returns an undefined value.
Defines a number.
171 172 173 |
# File 'lib/apiwork/element.rb', line 171 def number(max: nil, min: nil) of(:number, max:, min:) end |
#object {|object| ... } ⇒ void
This method returns an undefined value.
Defines an object.
288 289 290 |
# File 'lib/apiwork/element.rb', line 288 def object(&block) of(:object, &block) end |
#of(type, **options, &block) ⇒ Object
404 405 406 |
# File 'lib/apiwork/element.rb', line 404 def of(type, **, &block) raise NotImplementedError, "#{self.class} must implement #of" end |
#record {|element| ... } ⇒ void
This method returns an undefined value.
Defines a record.
332 333 334 |
# File 'lib/apiwork/element.rb', line 332 def record(&block) of(:record, &block) end |
#reference(type_name) ⇒ void
This method returns an undefined value.
Defines a reference to a named type.
396 397 398 |
# File 'lib/apiwork/element.rb', line 396 def reference(type_name) of(type_name) end |
#string(enum: nil, format: nil, max: nil, min: nil) ⇒ void
This method returns an undefined value.
Defines a string.
103 104 105 |
# File 'lib/apiwork/element.rb', line 103 def string(enum: nil, format: nil, max: nil, min: nil) of(:string, enum:, format:, max:, min:) end |
#time ⇒ void
This method returns an undefined value.
Defines a time.
236 237 238 |
# File 'lib/apiwork/element.rb', line 236 def time of(:time) end |
#union(discriminator: nil) {|union| ... } ⇒ void
This method returns an undefined value.
Defines a union.
366 367 368 |
# File 'lib/apiwork/element.rb', line 366 def union(discriminator: nil, &block) of(:union, discriminator:, &block) end |
#unknown ⇒ void
This method returns an undefined value.
Defines an unknown.
262 263 264 |
# File 'lib/apiwork/element.rb', line 262 def unknown of(:unknown) end |
#uuid ⇒ void
This method returns an undefined value.
Defines a UUID.
223 224 225 |
# File 'lib/apiwork/element.rb', line 223 def uuid of(:uuid) end |
#validate! ⇒ Object
400 401 402 |
# File 'lib/apiwork/element.rb', line 400 def validate! raise ArgumentError, 'must define exactly one type' unless @defined end |