Class: EasyTalk::Builders::UnionBuilder

Inherits:
Object
  • Object
show all
Extended by:
CollectionHelpers, T::Sig
Defined in:
lib/easy_talk/builders/union_builder.rb

Overview

Base builder class for array-type properties.

Constant Summary collapse

VALID_OPTIONS =
%i[title description optional as validate].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, constraints) ⇒ UnionBuilder

Returns a new instance of UnionBuilder.



16
17
18
19
20
21
22
# File 'lib/easy_talk/builders/union_builder.rb', line 16

def initialize(name, type, constraints)
  EasyTalk.assert_valid_property_options(name, constraints, VALID_OPTIONS)
  @name = name
  @type = type
  @constraints = constraints
  @context = {}
end

Class Method Details

.collection_type?Boolean Originally defined in module CollectionHelpers

Returns:

  • (Boolean)

Instance Method Details

#buildObject



25
26
27
28
29
# File 'lib/easy_talk/builders/union_builder.rb', line 25

def build
  @context[@name] = {
    'anyOf' => schemas
  }
end

#schemasObject



32
33
34
35
36
# File 'lib/easy_talk/builders/union_builder.rb', line 32

def schemas
  types.map do |type|
    Property.new(@name, type, @constraints).build
  end
end

#typesObject



39
40
41
# File 'lib/easy_talk/builders/union_builder.rb', line 39

def types
  @type.types
end