Sha256: 39092be940fc6c18e6df72b738110416d8ff92fccdcb5342e33512cf33246945

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Fluxus
  require 'fluxus/results/success'
  require 'fluxus/results/failure'

  class Runner
    class ResultTypeNotDefinedError < StandardError; end
    class CallerNotImplemented < StandardError; end

    private_class_method :new

    def self.call!(...)
      raise CallerNotImplemented, 'the flow must be implemented by a caller'
    end

    def self.__call__(instance, ...)
      result = instance.call!(...)
      raise ResultTypeNotDefinedError, 'flow results must be Success or Failure' unless result.is_a?(Results::Result)

      result
    end
    private_class_method :__call__

    def call!
      raise NotImplementedError, '#call! must be implemented'
    end

    # rubocop:disable Naming/MethodName
    def Success(type: :ok, result: nil)
      @__result = Results::Success.new(type: type, data: result)
    end

    def Failure(type: :error, result: nil)
      @__result = Results::Failure.new(type: type, data: result)
    end
    # rubocop:enable Naming/MethodName

    private

    attr_reader :__result
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fluxus-1.0.0 lib/fluxus/runner.rb
fluxus-0.1.2 lib/fluxus/runner.rb
fluxus-0.1.0 lib/fluxus/runner.rb