Class: EasyTalk::Builders::TupleBuilder

Inherits:
BaseBuilder show all
Extended by:
T::Sig
Defined in:
lib/easy_talk/builders/tuple_builder.rb

Overview

Builder class for tuple array properties (T::Tuple[Type1, Type2, ...]).

Tuples are arrays with positional type validation where each index has a specific expected type.

Examples:

Basic tuple

property :coordinates, T::Tuple[Float, Float]

Tuple with additional items constraint

property :record, T::Tuple[String, Integer], additional_items: false

Constant Summary collapse

VALID_OPTIONS =

NOTE: additional_items is handled separately in build() since it can be a type

{
  min_items: { type: Integer, key: :minItems },
  max_items: { type: Integer, key: :maxItems },
  unique_items: { type: T::Boolean, key: :uniqueItems }
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, constraints = {}) ⇒ TupleBuilder

Returns a new instance of TupleBuilder.



30
31
32
33
34
35
36
37
38
# File 'lib/easy_talk/builders/tuple_builder.rb', line 30

def initialize(name, type, constraints = {})
  @name = name
  @type = type
  # Work on a copy to avoid mutating the original constraints hash
  local_constraints = constraints.dup
  # Extract additional_items before passing to super (it's handled separately in build)
  @additional_items_constraint = local_constraints.delete(:additional_items)
  super(name, { type: 'array' }, local_constraints, VALID_OPTIONS)
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



27
28
29
# File 'lib/easy_talk/builders/tuple_builder.rb', line 27

def type
  @type
end

Class Method Details

.collection_type?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/easy_talk/builders/tuple_builder.rb', line 41

def self.collection_type?
  true
end

Instance Method Details

#buildObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/easy_talk/builders/tuple_builder.rb', line 49

def build
  schema = super

  # Build items array from tuple types
  schema[:items] = build_items

  # Handle additional_items constraint
  schema[:additionalItems] = build_additional_items_schema(@additional_items_constraint) unless @additional_items_constraint.nil?

  schema
end