module Dry::Types

def self.[](name)

Other tags:
    Api: - public

Returns:
  • (Type, Class) -

Parameters:
  • name (String, Class) --
def self.[](name)
  type_map.fetch_or_store(name) do
    case name
    when ::String
      result = name.match(TYPE_SPEC_REGEX)
      if result
        type_id, member_id = result[1..2]
        container[type_id].of(self[member_id])
      else
        container[name]
      end
    when ::Class
      warn(<<~DEPRECATION)
        Using Dry::Types.[] with a class is deprecated, please use string identifiers: Dry::Types[Integer] -> Dry::Types['integer'].
        If you're using dry-struct this means changing `attribute :counter, Integer` to `attribute :counter, Dry::Types['integer']` or to `attribute :counter, 'integer'`.
      DEPRECATION
      type_name = identifier(name)
      if container.key?(type_name)
        self[type_name]
      else
        name
      end
    end
  end
end