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.
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.
42 43 44 45 46 47 48 49 |
# File 'lib/flows/plugin/output_contract/wrapper.rb', line 42 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, 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.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/flows/plugin/output_contract/wrapper.rb', line 31 def transform_result(klass, result) contract = Util.contract_for(klass, 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 |