Module: Remap::Operation

Included in:
Base, Mapper::Binary
Defined in:
lib/remap/operation.rb

Overview

Class interface for Base and instance interface for Mapper

Instance Method Summary collapse

Instance Method Details

#call(input, **options) {|Failure| ... } ⇒ Success

Public interface for mappers

Parameters:

  • input (Any)

    Data to be mapped

  • options (Hash)

    Mapper arguments

Yields:

Returns:

  • (Success)

    if mapper succeeds



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/remap/operation.rb', line 16

def call(input, **options, &error)
  unless error
    return call(input, **options) do |failure|
      raise failure.exception
    end
  end

  other = State.call(input, options: options, mapper: self).then do |state|
    call!(state) do |failure|
      return error[failure]
    end
  end

  case other
  in { value: }
    value
  in { notices: [] }
    error[other.failure("No return value")]
  in { notices: }
    error[Failure.call(failures: notices)]
  end
end