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
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#property_name ⇒ Object
readonly
Returns the value of attribute property_name.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(property_name, schema, options = {}, valid_options = {}) ⇒ BaseBuilder
constructor
Initializes a new instance of the BaseBuilder class.
Constructor Details
#initialize(property_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(property_name, schema, = {}, = {}) @valid_options = COMMON_OPTIONS.merge() EasyTalk.(property_name, , @valid_options.keys) @property_name = property_name @schema = schema @options = end |
Instance Attribute Details
#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 |
#property_name ⇒ Object (readonly)
Returns the value of attribute property_name.
18 19 20 |
# File 'lib/easy_talk/builders/base_builder.rb', line 18 def property_name @property_name 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
60 61 62 |
# File 'lib/easy_talk/builders/base_builder.rb', line 60 def self.collection_type? false end |
Instance Method Details
#build ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/easy_talk/builders/base_builder.rb', line 44 def build @valid_options.each_with_object(schema) do |(constraint_name, value), obj| next if @options[constraint_name].nil? # Use our centralized validation ErrorHelper.validate_constraint_value( property_name: property_name, constraint_name: constraint_name, value_type: value[:type], value: @options[constraint_name] ) obj[value[:key]] = @options[constraint_name] end end |