Sha256: 796b36c5db256eb398e8fc091bba55529f2f6841a414f7a161da35c633c1d8a8
Contents?: true
Size: 876 Bytes
Versions: 17
Compression:
Stored size: 876 Bytes
Contents
module Datacaster class ThenNode < Base def initialize(left, then_caster, else_caster = nil) @left = left @then = then_caster @else = else_caster end def else(else_caster) raise ArgumentError.new("Datacaster: double else clause is not permitted") if @else self.class.new(@left, @then, DefinitionDSL.expand(else_caster)) end def cast(object, runtime:) unless @else raise ArgumentError.new('Datacaster: use "a & b" instead of "a.then(b)" when there is no else-clause') end left_result = @left.with_runtime(runtime).(object) if left_result.valid? @then.with_runtime(runtime).(left_result.value) else @else.with_runtime(runtime).(object) end end def inspect "#<Datacaster::ThenNode Then: #{@then.inspect} Else: #{@else.inspect}>" end end end
Version data entries
17 entries across 17 versions & 1 rubygems