Module: Flows::Plugin::OutputContract::Wrapper::Util Private

Defined in:
lib/flows/plugin/output_contract/wrapper.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Helper methods for Flows::Plugin::OutputContract::Wrapper are extracted to this module as singleton methods to not pollute user classes.

Since:

  • 0.4.0

API:

  • private

Class Method Summary collapse

Class Method Details

.contract_for(klass, result) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

Since:

  • 0.4.0

API:

  • private



31
32
33
34
35
36
37
38
# File 'lib/flows/plugin/output_contract/wrapper.rb', line 31

def contract_for(klass, result)
  raise ResultTypeError.new(klass, result) unless result.is_a?(Flows::Result)

  status = result.status
  contracts = result.ok? ? klass.success_contracts : klass.failure_contracts

  contracts[status] || raise(StatusError.new(klass, result, contracts.keys))
end

.transform_result(klass, contract, result) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

Since:

  • 0.4.0

API:

  • private



40
41
42
43
44
45
46
47
# File 'lib/flows/plugin/output_contract/wrapper.rb', line 40

def transform_result(klass, contract, result)
  data = result.send(:data)

  transformed_result = contract.transform(data)
  raise ContractError.new(klass, result, transformed_result.error) if transformed_result.err?

  result.send(:'data=', transformed_result.unwrap)
end