Module: Atacama::Types
- Defined in:
- lib/atacama/types.rb
Overview
The type namespace to interact with DRY::Types
Constant Summary collapse
- Boolean =
Types::True | Types::False
Class Method Summary collapse
-
.Option(**map) ⇒ Dry::Type
Defines a type which checks that the Option value contains a valid data structure.
-
.Return(type) ⇒ Dry::Type
Defines a type which checks that the Return value contains a valid object.
Class Method Details
.Option(**map) ⇒ Dry::Type
Defines a type which checks that the Option value contains a valid data structure.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/atacama/types.rb', line 16 def self.Option(**map) Instance(Values::Option).constructor do |value_object| if value_object.is_a? Values::Option map.each do |key, type| value = value_object.value[key] Atacama.check(type, value) do |e| raise OptionTypeMismatchError, Atacama.format_exception(self, e, "The Option() #{key.inspect} value #{value.inspect} is the incorrect type." ) end end end value_object end end |
.Return(type) ⇒ Dry::Type
Defines a type which checks that the Return value contains a valid object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/atacama/types.rb', line 39 def self.Return(type) Instance(Values::Return).constructor do |value_object| if value_object.is_a?(Values::Return) Atacama.check(type, value_object.value) do |e| raise ReturnTypeMismatchError, Atacama.format_exception(self, e, "The Return() value #{value_object.value.inspect} does not match the declared type." ) end end value_object end end |