Class: T::Private::Types::TypeAlias
- Inherits:
-
Types::Base
- Object
- Types::Base
- T::Private::Types::TypeAlias
- Defined in:
- lib/types/private/types/type_alias.rb
Overview
Wraps a proc for a type alias to defer its evaluation.
Instance Method Summary collapse
- #aliased_type ⇒ Object
- #build_type ⇒ Object
- #checked(level) ⇒ Object
- #effective_aliased_type ⇒ Object
-
#initialize(callable) ⇒ TypeAlias
constructor
A new instance of TypeAlias.
-
#name ⇒ Object
overrides Base.
-
#recursively_valid?(obj) ⇒ Boolean
overrides Base.
-
#valid?(obj) ⇒ Boolean
overrides Base.
Methods inherited from Types::Base
#==, #describe_obj, #error_message_for_obj, #error_message_for_obj_recursive, #hash, method_added, #subtype_of?, #to_s, #validate!
Constructor Details
#initialize(callable) ⇒ TypeAlias
Returns a new instance of TypeAlias.
8 9 10 11 |
# File 'lib/types/private/types/type_alias.rb', line 8 def initialize(callable) @callable = callable @checked_level = nil end |
Instance Method Details
#aliased_type ⇒ Object
28 29 30 |
# File 'lib/types/private/types/type_alias.rb', line 28 def aliased_type @aliased_type ||= T::Utils.coerce(@callable.call) end |
#build_type ⇒ Object
24 25 26 |
# File 'lib/types/private/types/type_alias.rb', line 24 def build_type nil end |
#checked(level) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/types/private/types/type_alias.rb', line 13 def checked(level) if !@checked_level.nil? raise "You can't call .checked multiple times on a type alias." end if !T::Private::RuntimeLevels::LEVELS.include?(level) raise ArgumentError.new("Invalid `checked` level '#{level}'. Use one of: #{T::Private::RuntimeLevels::LEVELS}.") end @checked_level = level self end |
#effective_aliased_type ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/types/private/types/type_alias.rb', line 32 def effective_aliased_type @effective_aliased_type ||= begin real_type = aliased_type level = @checked_level.nil? ? T::Private::RuntimeLevels.default_checked_level : @checked_level if level == :always || (level == :tests && T::Private::RuntimeLevels.check_tests?) real_type else T::Types::Anything::Private::INSTANCE end end end |
#name ⇒ Object
overrides Base
45 46 47 |
# File 'lib/types/private/types/type_alias.rb', line 45 def name aliased_type.name end |
#recursively_valid?(obj) ⇒ Boolean
overrides Base
50 51 52 |
# File 'lib/types/private/types/type_alias.rb', line 50 def recursively_valid?(obj) effective_aliased_type.recursively_valid?(obj) end |
#valid?(obj) ⇒ Boolean
overrides Base
55 56 57 |
# File 'lib/types/private/types/type_alias.rb', line 55 def valid?(obj) effective_aliased_type.valid?(obj) end |