class Typed::Builder::CoerceType
Attributes
coercion[R]
input_type[R]
return_type[R]
swallow[R]
Public Class Methods
new(input_type, return_type, swallow, &coercion)
click to toggle source
# File lib/typed/builder.rb, line 206 def initialize(input_type, return_type, swallow, &coercion) @input_type = input_type @return_type = return_type @coercion = coercion @swallow = swallow end
Public Instance Methods
process(value)
click to toggle source
# File lib/typed/builder.rb, line 213 def process(value) # No coercion needed passthrough_result = return_type.process(value) return passthrough_result if passthrough_result.ok # Check input_type enables this coercion input_result = input_type.process(value) if input_result.ok coerced_value = begin coercion.call(input_result.value) rescue *swallow input_result.value end return return_type.process(coerced_value) end passthrough_result end