Class: EasyTalk::Builders::StringBuilder

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

Overview

Builder class for string properties.

Direct Known Subclasses

TemporalBuilder

Constant Summary collapse

VALID_OPTIONS =
{
  format: { type: String, key: :format },
  pattern: { type: String, key: :pattern },
  min_length: { type: Integer, key: :minLength },
  max_length: { type: Integer, key: :maxLength },
  enum: { type: T::Array[String], key: :enum },
  const: { type: String, key: :const },
  default: { type: String, key: :default }
}.freeze

Constants inherited from BaseBuilder

BaseBuilder::COMMON_OPTIONS

Instance Attribute Summary

Attributes inherited from BaseBuilder

#options, #property_name, #schema

Instance Method Summary collapse

Methods inherited from BaseBuilder

collection_type?

Constructor Details

#initialize(name, constraints = {}) ⇒ StringBuilder

Returns a new instance of StringBuilder.



24
25
26
# File 'lib/easy_talk/builders/string_builder.rb', line 24

def initialize(name, constraints = {})
  super(name, { type: 'string' }, constraints, VALID_OPTIONS)
end

Instance Method Details

#buildObject



28
29
30
31
32
33
# File 'lib/easy_talk/builders/string_builder.rb', line 28

def build
  super.tap do |schema|
    pattern = schema[:pattern]
    schema[:pattern] = JsRegex.new(pattern).source if pattern.is_a?(String)
  end
end