Class: Skit::JsonSchema::Definitions::UnionPropertyType

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/skit/json_schema/definitions/union_property_type.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(types:, nullable: false) ⇒ UnionPropertyType

Returns a new instance of UnionPropertyType.



22
23
24
25
# File 'lib/skit/json_schema/definitions/union_property_type.rb', line 22

def initialize(types:, nullable: false)
  @types = types
  @nullable = nullable
end

Instance Attribute Details

#nullableObject (readonly)

Returns the value of attribute nullable.



14
15
16
# File 'lib/skit/json_schema/definitions/union_property_type.rb', line 14

def nullable
  @nullable
end

#typesObject (readonly)

Returns the value of attribute types.



11
12
13
# File 'lib/skit/json_schema/definitions/union_property_type.rb', line 11

def types
  @types
end

Instance Method Details

#to_sorbet_typeObject



28
29
30
31
# File 'lib/skit/json_schema/definitions/union_property_type.rb', line 28

def to_sorbet_type
  union_str = "T.any(#{@types.map(&:to_sorbet_type).join(", ")})"
  @nullable ? "T.nilable(#{union_str})" : union_str
end

#with_nullableObject



34
35
36
# File 'lib/skit/json_schema/definitions/union_property_type.rb', line 34

def with_nullable
  UnionPropertyType.new(types: @types, nullable: true)
end