module Flows::Result::Helpers

Shortcuts for building and matching result objects.

`:reek:UtilityFunction` and `:reek:FeatureEnvy` checks should be disabled here because this module is intended to contain private utility methods only.

This module defines the following private methods:

@see Flows::Result usage examples provided here

Private Instance Methods

err(status = :err, **data) click to toggle source
# File lib/flows/result/helpers.rb, line 29
def err(status = :err, **data)
  Flows::Result::Err.new(data, status: status)
end
err_data(data, status: :err) click to toggle source
# File lib/flows/result/helpers.rb, line 33
def err_data(data, status: :err)
  Flows::Result::Err.new(data, status: status)
end
match_err(status = nil) click to toggle source
# File lib/flows/result/helpers.rb, line 48
def match_err(status = nil)
  if status
    lambda do |result|
      result.is_a?(Flows::Result::Err) &&
        result.status == status
    end
  else
    Flows::Result::Err
  end
end
match_ok(status = nil) click to toggle source
# File lib/flows/result/helpers.rb, line 37
def match_ok(status = nil)
  if status
    lambda do |result|
      result.is_a?(Flows::Result::Ok) &&
        result.status == status
    end
  else
    Flows::Result::Ok
  end
end
ok(status = :ok, **data) click to toggle source
# File lib/flows/result/helpers.rb, line 21
def ok(status = :ok, **data)
  Flows::Result::Ok.new(data, status: status)
end
ok_data(data, status: :ok) click to toggle source
# File lib/flows/result/helpers.rb, line 25
def ok_data(data, status: :ok)
  Flows::Result::Ok.new(data, status: status)
end