Module: FlowOrganizer::Callable

Defined in:
lib/flow_organizer/callable.rb

Overview

This module makes FlowOrganizer extensible. You can add your own behaviours to resolve callables.

Defined Under Namespace

Modules: Alias, Branch

Class Method Summary collapse

Class Method Details

.resolve(target:) ⇒ Object

Transform each target to a callable. This is delegated to submodules registered in the local ‘store`.

Parameters:

  • target

    A callable or some data that can be transformed to a callable

Returns:

  • A callable



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/flow_organizer/callable.rb', line 16

def self.resolve(target:)
  if target.respond_to?(:call)
    [:ok, callable: target]
  else
    type = target[0]
    if store[type]
      store[type].call(args: target)
    else
      [:error, "FlowOrganizer could not resolve callable type `#{ type }`"]
    end
  end
end

.storeObject

Local store to add custom behaviours.



6
7
8
9
10
11
# File 'lib/flow_organizer/callable.rb', line 6

def self.store
  @store ||= {
    alias:  FlowOrganizer::Callable::Alias.method(:resolve),
    branch: FlowOrganizer::Callable::Branch.method(:resolve),
  }
end