Module: T

Defined in:
lib/ding_sdk/utils/t.rb

Overview

typed: true frozen_string_literal: true

Class Method Summary collapse

Class Method Details

.arr?(t) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
# File 'lib/ding_sdk/utils/t.rb', line 7

def self.arr?(t)
  if t.respond_to? :underlying_class
    return t.underlying_class == ::Array
  end
  false
end

.arr_of(t) ⇒ Object



14
15
16
# File 'lib/ding_sdk/utils/t.rb', line 14

def self.arr_of(t)
  get_raw_type(t.type)
end

.get_raw_type(t) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/ding_sdk/utils/t.rb', line 51

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

.hash?(t) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
# File 'lib/ding_sdk/utils/t.rb', line 18

def self.hash?(t)
  if t.respond_to? :underlying_class
    return t.underlying_class == ::Hash
  end
  false
end

.hash_of(t) ⇒ Object



25
26
27
# File 'lib/ding_sdk/utils/t.rb', line 25

def self.hash_of(t)
  get_raw_type(t.values)
end

.nilable?(t) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/ding_sdk/utils/t.rb', line 29

def self.nilable?(t)
  t.respond_to? :unwrap_nilable
end

.nilable_of(t) ⇒ Object



33
34
35
36
37
38
# File 'lib/ding_sdk/utils/t.rb', line 33

def self.nilable_of(t)
  if t.respond_to? :unwrap_nilable
    return simplify_type t.unwrap_nilable
  end
  nil
end

.simplifiable?(t) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/ding_sdk/utils/t.rb', line 40

def self.simplifiable?(t)
  return t.is_a? T::Types::Simple
end

.simplify_type(t) ⇒ Object



44
45
46
47
48
49
# File 'lib/ding_sdk/utils/t.rb', line 44

def self.simplify_type(t)
  if t.is_a? T::Types::Simple
    return t.raw_type
  end
  t
end