Module: Dry::Data::TypeBuilder

Included in:
Constrained, Default, Optional, Safe, Type
Defined in:
lib/dry/data/type_builder.rb

Instance Method Summary collapse

Instance Method Details

#constrained(options) ⇒ Object



12
13
14
# File 'lib/dry/data/type_builder.rb', line 12

def constrained(options)
  Constrained.new(self, rule: Data.Rule(primitive, options))
end

#default(value) ⇒ Object



16
17
18
# File 'lib/dry/data/type_builder.rb', line 16

def default(value)
  Default.new(self, value: value)
end

#enum(*values) ⇒ Object



20
21
22
# File 'lib/dry/data/type_builder.rb', line 20

def enum(*values)
  Enum.new(constrained(inclusion: values), values: values)
end

#optionalObject



8
9
10
# File 'lib/dry/data/type_builder.rb', line 8

def optional
  Optional.new(Data['nil'] | self)
end

#safeObject



24
25
26
# File 'lib/dry/data/type_builder.rb', line 24

def safe
  Safe.new(self)
end

#|(other) ⇒ Object



4
5
6
# File 'lib/dry/data/type_builder.rb', line 4

def |(other)
  SumType.new(self, other)
end