Class: EasyTalk::Builders::CompositionBuilder
- Inherits:
-
Object
- Object
- EasyTalk::Builders::CompositionBuilder
- Extended by:
- CollectionHelpers, T::Sig
- Defined in:
- lib/easy_talk/builders/composition_builder.rb
Overview
This class represents a builder for composing JSON schemas using the “allOf”, “anyOf”, or “oneOf” keywords.
Direct Known Subclasses
Constant Summary collapse
- COMPOSER_TO_KEYWORD =
{ 'AllOfBuilder' => 'allOf', 'AnyOfBuilder' => 'anyOf', 'OneOfBuilder' => 'oneOf' }.freeze
Instance Method Summary collapse
-
#build ⇒ void
Builds the composed JSON schema.
-
#composer_keyword ⇒ String
Returns the composer keyword based on the composer type.
-
#initialize(name, type, _constraints) ⇒ CompositionBuilder
constructor
Initializes a new instance of the CompositionBuilder class.
-
#items ⇒ T.untyped
Returns the items of the type.
-
#schemas ⇒ Array<Hash>
Returns an array of schemas for the composed JSON schema.
Methods included from CollectionHelpers
Constructor Details
#initialize(name, type, _constraints) ⇒ CompositionBuilder
Initializes a new instance of the CompositionBuilder class.
24 25 26 27 28 29 |
# File 'lib/easy_talk/builders/composition_builder.rb', line 24 def initialize(name, type, _constraints) @composer_type = self.class.name.split('::').last @name = name @type = type @context = {} end |
Instance Method Details
#build ⇒ void
This method returns an undefined value.
Builds the composed JSON schema.
34 35 36 37 38 39 |
# File 'lib/easy_talk/builders/composition_builder.rb', line 34 def build @context[@name.to_sym] = { type: 'object', composer_keyword => schemas } end |
#composer_keyword ⇒ String
Returns the composer keyword based on the composer type.
44 45 46 |
# File 'lib/easy_talk/builders/composition_builder.rb', line 44 def composer_keyword COMPOSER_TO_KEYWORD[@composer_type] end |
#items ⇒ T.untyped
Returns the items of the type.
60 61 62 |
# File 'lib/easy_talk/builders/composition_builder.rb', line 60 def items @type.items end |
#schemas ⇒ Array<Hash>
Returns an array of schemas for the composed JSON schema.
51 52 53 54 55 |
# File 'lib/easy_talk/builders/composition_builder.rb', line 51 def schemas items.map do |type| type.respond_to?(:schema) ? type.schema : { type: type.to_s.downcase } end end |