Class: Skit::JsonSchema::Definitions::ConstType
- Inherits:
-
Object
- Object
- Skit::JsonSchema::Definitions::ConstType
- Extended by:
- T::Sig
- Defined in:
- lib/skit/json_schema/definitions/const_type.rb
Overview
Represents a JSON Schema const value type.
This generates a Skit::JsonSchema::Types::Const subclass that matches a specific constant value.
Instance Attribute Summary collapse
-
#class_name ⇒ Object
readonly
Returns the value of attribute class_name.
-
#nullable ⇒ Object
readonly
Returns the value of attribute nullable.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(class_name:, value:, nullable: false) ⇒ ConstType
constructor
A new instance of ConstType.
- #to_sorbet_type ⇒ Object
- #value_literal ⇒ Object
- #with_nullable ⇒ Object
Constructor Details
#initialize(class_name:, value:, nullable: false) ⇒ ConstType
Returns a new instance of ConstType.
30 31 32 33 34 |
# File 'lib/skit/json_schema/definitions/const_type.rb', line 30 def initialize(class_name:, value:, nullable: false) @class_name = class_name @value = value @nullable = nullable end |
Instance Attribute Details
#class_name ⇒ Object (readonly)
Returns the value of attribute class_name.
15 16 17 |
# File 'lib/skit/json_schema/definitions/const_type.rb', line 15 def class_name @class_name end |
#nullable ⇒ Object (readonly)
Returns the value of attribute nullable.
21 22 23 |
# File 'lib/skit/json_schema/definitions/const_type.rb', line 21 def nullable @nullable end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
18 19 20 |
# File 'lib/skit/json_schema/definitions/const_type.rb', line 18 def value @value end |
Instance Method Details
#to_sorbet_type ⇒ Object
37 38 39 |
# File 'lib/skit/json_schema/definitions/const_type.rb', line 37 def to_sorbet_type nullable ? "T.nilable(#{@class_name})" : @class_name end |
#value_literal ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/skit/json_schema/definitions/const_type.rb', line 49 def value_literal case @value when String @value.inspect when Integer, Float @value.to_s when TrueClass "true" when FalseClass "false" else # This branch should never be reached due to validation in SchemaAnalyzer @value.inspect end end |