Module: Uinit::Type::Context

Defined in:
lib/uinit/type/context.rb

Constant Summary collapse

Nil =
Const[nil].freeze
Boolean =
(Const[true] | Const[false]).freeze
Str =
TypeOf[String].freeze
Sym =
TypeOf[Symbol].freeze
Int =
TypeOf[Integer].freeze
Float =
TypeOf[Float].freeze
Hsh =
TypeOf[Hash].freeze
Arr =
TypeOf[Array].freeze

Instance Method Summary collapse

Instance Method Details

#any_of(const, *consts) ⇒ Object



19
20
21
# File 'lib/uinit/type/context.rb', line 19

def any_of(const, *consts)
  consts.reduce(Const[const]) { |type, cst| type | Const[cst] }
end

#arrayObject



84
85
86
# File 'lib/uinit/type/context.rb', line 84

def array
  Arr
end

#array_of(type) ⇒ Object



15
16
17
# File 'lib/uinit/type/context.rb', line 15

def array_of(type)
  ArrayOf.new(type)
end

#booleanObject Also known as: bool



61
62
63
# File 'lib/uinit/type/context.rb', line 61

def boolean
  Boolean
end

#check(check = nil, &proc_check) ⇒ Object



23
24
25
# File 'lib/uinit/type/context.rb', line 23

def check(check = nil, &proc_check)
  Check.new(check || proc_check)
end

#const(const) ⇒ Object



27
28
29
# File 'lib/uinit/type/context.rb', line 27

def const(const)
  Const.new(const)
end

#floatObject



76
77
78
# File 'lib/uinit/type/context.rb', line 76

def float
  Float
end

#fn(arity = -1)) ⇒ Object



31
32
33
# File 'lib/uinit/type/context.rb', line 31

def fn(arity = -1)
  Fn.new(arity)
end

#hashObject



80
81
82
# File 'lib/uinit/type/context.rb', line 80

def hash
  Hsh
end

#hash_of(schema, strict: false) ⇒ Object



35
36
37
# File 'lib/uinit/type/context.rb', line 35

def hash_of(schema, strict: false)
  HashOf.new(schema, strict:)
end

#implObject



39
40
41
# File 'lib/uinit/type/context.rb', line 39

def impl(*, **)
  Impl.new(*, **)
end

#integerObject Also known as: int



71
72
73
# File 'lib/uinit/type/context.rb', line 71

def integer
  Int
end

#nilableObject Also known as: null, none



55
56
57
# File 'lib/uinit/type/context.rb', line 55

def nilable
  Nil
end

#set_of(type) ⇒ Object

rubocop:disable Naming/AccessorMethodName



43
44
45
# File 'lib/uinit/type/context.rb', line 43

def set_of(type) # rubocop:disable Naming/AccessorMethodName
  SetOf.new(type)
end

#stringObject Also known as: str



66
67
68
# File 'lib/uinit/type/context.rb', line 66

def string
  Str
end

#symObject



88
89
90
# File 'lib/uinit/type/context.rb', line 88

def sym
  Sym
end

#type(type = BasicObject) ⇒ Object



47
48
49
# File 'lib/uinit/type/context.rb', line 47

def type(type = BasicObject)
  Type.new(type)
end

#type_of(type) ⇒ Object



51
52
53
# File 'lib/uinit/type/context.rb', line 51

def type_of(type)
  TypeOf.new(type)
end