Class: EasyTalk::Builders::TupleBuilder
- Inherits:
-
BaseBuilder
- Object
- BaseBuilder
- EasyTalk::Builders::TupleBuilder
- 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.
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
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(name, type, constraints = {}) ⇒ TupleBuilder
constructor
A new instance of TupleBuilder.
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
#type ⇒ Object (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
41 42 43 |
# File 'lib/easy_talk/builders/tuple_builder.rb', line 41 def self.collection_type? true end |
Instance Method Details
#build ⇒ Object
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 |