Module: Flows::Result::Do::Util Private

Defined in:
lib/flows/result/do.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.

Utility functions for Flows::Result::Do.

Isolated location prevents polluting user classes with unnecessary methods.

Since:

  • 0.4.0

Class Method Summary collapse

Class Method Details

.define_wrapper(mod, method_name) ⇒ 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.

:reek:TooManyStatements - allowed because we have no choice here.

:reek:NestedIterators - allowed here because here are no iterators.

Since:

  • 0.4.0



149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/flows/result/do.rb', line 149

def define_wrapper(mod, method_name) # rubocop:disable Metrics/MethodLength
  mod.define_method(method_name) do |*args|
    super(*args) do |*fields, result|
      case result
      when Flows::Result::Ok
        data = result.unwrap
        fields.any? ? data.values_at(*fields) : data
      when Flows::Result::Err then return result
      else raise "Unexpected result: #{result.inspect}. Should be a Flows::Result"
      end
    end
  end
end

.fetch_and_prepend_module(mod) ⇒ 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.

Since:

  • 0.4.0



140
141
142
143
144
# File 'lib/flows/result/do.rb', line 140

def fetch_and_prepend_module(mod)
  module_for_do = mod.instance_variable_get(MOD_VAR_NAME)
  mod.prepend(module_for_do)
  module_for_do
end