Sha256: ae0120f8b14fead96eb5adf3eb3644d4a65fdb81568cb19453194607fd810486

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module Micro
  class Case
    class Safe
      module Flow
        def self.included(base)
          base.send(:include, ::Micro::Case::Flow)

          def base.flow_reducer; Reducer; end
        end

        class Reducer < ::Micro::Case::Flow::Reducer
          alias_method :&, :>>

          def >>(arg)
            raise NoMethodError, "undefined method `>>' for #{self.inspect}. Please, use the method `&' to avoid this error."
          end

          private

            def next_use_case_result(use_case, result, input)
              begin
                instance = use_case.__new__(result, input)
                instance.call
              rescue => exception
                raise exception if Error::ByWrongUsage.check(exception)

                result.__set__(false, exception, :exception, instance)
              end
            end
        end
      end

      def self.Flow(args)
        Flow::Reducer.build(Array(args))
      end

      def self.__flow_reducer
        Flow::Reducer
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
u-case-2.6.0 lib/micro/case/safe/flow.rb
u-case-2.5.0 lib/micro/case/safe/flow.rb
u-case-2.4.0 lib/micro/case/safe/flow.rb