Class: EasyTalk::Builders::BaseBuilder
- Inherits:
-
Object
- Object
- EasyTalk::Builders::BaseBuilder
- Extended by:
- T::Sig
- Defined in:
- lib/easy_talk/builders/base_builder.rb
Overview
BaseBuilder is a class that provides a common structure for building schema properties
Direct Known Subclasses
BooleanBuilder, IntegerBuilder, NullBuilder, NumberBuilder, ObjectBuilder, StringBuilder, TypedArrayBuilder
Constant Summary collapse
- COMMON_OPTIONS =
BaseBuilder is a class that provides a common structure for building objects representing schema properties.
{ title: { type: T.nilable(String), key: :title }, description: { type: T.nilable(String), key: :description }, optional: { type: T.nilable(T::Boolean), key: :optional } }.freeze
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(name, schema, options = {}, valid_options = {}) ⇒ BaseBuilder
constructor
Initializes a new instance of the BaseBuilder class.
Constructor Details
#initialize(name, schema, options = {}, valid_options = {}) ⇒ BaseBuilder
Initializes a new instance of the BaseBuilder class.
34 35 36 37 38 39 40 |
# File 'lib/easy_talk/builders/base_builder.rb', line 34 def initialize(name, schema, = {}, = {}) @valid_options = COMMON_OPTIONS.merge() .assert_valid_keys(@valid_options.keys) @name = name @schema = schema @options = end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
18 19 20 |
# File 'lib/easy_talk/builders/base_builder.rb', line 18 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
18 19 20 |
# File 'lib/easy_talk/builders/base_builder.rb', line 18 def @options end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
18 19 20 |
# File 'lib/easy_talk/builders/base_builder.rb', line 18 def schema @schema end |
Class Method Details
.collection_type? ⇒ Boolean
58 59 60 |
# File 'lib/easy_talk/builders/base_builder.rb', line 58 def self.collection_type? false end |
Instance Method Details
#build ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/easy_talk/builders/base_builder.rb', line 44 def build @valid_options.each_with_object(schema) do |(key, value), obj| next if @options[key].nil? # Work around for Sorbet's default inability to type check the items inside an array if value[:type].respond_to?(:recursively_valid?) && !value[:type].recursively_valid?(@options[key]) raise TypeError, "Invalid type for #{key}" end obj[value[:key]] = T.let(@options[key], value[:type]) end end |