Module: TypeSpecFromSerializers::RBI::Types

Defined in:
lib/typespec_from_serializers/rbi.rb

Overview

Internal: Reusable type builders for common Sorbet types.

Class Method Summary collapse

Class Method Details

.array_of_hashesObject

T::Array[T::Hash[Symbol, T.untyped]]



30
31
32
# File 'lib/typespec_from_serializers/rbi.rb', line 30

def array_of_hashes
  @array_of_hashes ||= ::RBI::Type.generic("T::Array", [hash])
end

.hashObject

T::Hash[Symbol, T.untyped]



17
18
19
20
21
22
# File 'lib/typespec_from_serializers/rbi.rb', line 17

def hash
  @hash ||= ::RBI::Type.generic("T::Hash", [
    ::RBI::Type.simple("Symbol"),
    ::RBI::Type.untyped,
  ])
end

.items_type(model_type) ⇒ Object

T.any(T::Array, ActiveRecord::Relation)



35
36
37
38
39
40
# File 'lib/typespec_from_serializers/rbi.rb', line 35

def items_type(model_type)
  ::RBI::Type.any(
    ::RBI::Type.generic("T::Array", [::RBI::Type.simple(model_type)]),
    ::RBI::Type.simple("ActiveRecord::Relation"),
  )
end

.optional_hashObject

T.nilable(T::Hash[Symbol, T.untyped])



25
26
27
# File 'lib/typespec_from_serializers/rbi.rb', line 25

def optional_hash
  @optional_hash ||= ::RBI::Type.nilable(hash)
end