Module: T::Utils::Private

Defined in:
lib/types/utils.rb

Class Method Summary collapse

Class Method Details

.coerce_and_check_module_types(val, check_val, check_module_type) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/types/utils.rb', line 6

def self.coerce_and_check_module_types(val, check_val, check_module_type)
  if val.is_a?(T::Types::Base)
    if val.is_a?(T::Private::Types::TypeAlias)
      val.aliased_type
    else
      val
    end
  elsif val.is_a?(Module)
    if check_module_type && check_val.is_a?(val)
      nil
    else
      T::Types::Simple::Private::Pool.type_for_module(val)
    end
  elsif val.is_a?(::Array)
    T::Types::FixedArray.new(val)
  elsif val.is_a?(::Hash)
    T::Types::FixedHash.new(val)
  elsif val.is_a?(T::Private::Methods::DeclBuilder)
    T::Private::Methods.finalize_proc(val.decl)
  elsif val.is_a?(::T::Enum)
    T::Types::TEnum.new(val)
  elsif val.is_a?(::String)
    raise "Invalid String literal for type constraint. Must be an #{T::Types::Base}, a " \
          "class/module, or an array. Got a String with value `#{val}`."
  else
    raise "Invalid value for type constraint. Must be an #{T::Types::Base}, a " \
          "class/module, or an array. Got a `#{val.class}`."
  end
end