mirror of
https://github.com/LukeHagar/plexruby.git
synced 2025-12-06 12:47:44 +00:00
79 lines
1.8 KiB
Ruby
79 lines
1.8 KiB
Ruby
# Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
|
|
# typed: true
|
|
# frozen_string_literal: true
|
|
|
|
module T
|
|
def self.arr?(t)
|
|
if t.respond_to? :underlying_class
|
|
return t.underlying_class == ::Array
|
|
end
|
|
false
|
|
end
|
|
|
|
def self.arr_of(t)
|
|
get_raw_type(t.type)
|
|
end
|
|
|
|
def self.hash?(t)
|
|
if t.respond_to? :underlying_class
|
|
return t.underlying_class == ::Hash
|
|
end
|
|
false
|
|
end
|
|
|
|
def self.hash_of(t)
|
|
get_raw_type(t.values)
|
|
end
|
|
|
|
def self.nilable?(t)
|
|
# in sorbet all `T.any` types provide unwrap_nilable for some reason
|
|
# So, in order to make this check more robust, we check if the type responds to the `types` method, and if so, whether
|
|
# one of those types is NilClass. For non-nilable unions, `types` will return a valid list that does not include NilClass
|
|
return false unless t.respond_to?(:unwrap_nilable)
|
|
return true unless t.respond_to?(:types)
|
|
t.types.map { |tt| simplify_type(tt) }.include?(NilClass)
|
|
end
|
|
|
|
def self.nilable_of(t)
|
|
|
|
if nilable t
|
|
return simplify_type t.unwrap_nilable
|
|
end
|
|
nil
|
|
end
|
|
|
|
def self.simplifiable?(t)
|
|
return t.is_a? T::Types::Simple
|
|
end
|
|
|
|
def self.simplify_type(t)
|
|
if t.is_a? T::Types::Simple
|
|
return t.raw_type
|
|
end
|
|
t
|
|
end
|
|
|
|
|
|
def self.union?(t)
|
|
return false unless t.respond_to? :types
|
|
return false if t.types.any? { |tt| get_raw_type(tt) == TrueClass }
|
|
return false if t.types.length == 2 && t.types.any? { |tt| get_raw_type(tt) == NilClass }
|
|
t.types.length > 1
|
|
end
|
|
|
|
def self.get_union_types(t)
|
|
t.types.map { |tt| get_raw_type(tt) }
|
|
end
|
|
|
|
|
|
def self.get_raw_type(t)
|
|
if t.respond_to? :raw_type
|
|
return t.raw_type
|
|
elsif t.respond_to? :raw_a
|
|
return T::Boolean if t.raw_a in [TrueClass, FalseClass]
|
|
end
|
|
t
|
|
end
|
|
end
|