Sha256: 9e12b9f68861bbcb13c4279a6cf19df69bd07abadfa77d02ea671974912e6f9b

Contents?: true

Size: 1007 Bytes

Versions: 5

Compression:

Stored size: 1007 Bytes

Contents

# frozen_string_literal: true

module Micro
  class Case
    module Flow
      module ClassMethods
        def __flow__
          @__flow
        end

        def flow(*args)
          @__flow = flow_reducer.build(args)
        end

        def call(options = {})
          new(options).call
        end
      end

      CONSTRUCTOR = <<-RUBY
      def initialize(options)
        @options = options

        flow = self.class.__flow__

        raise Error::UndefinedFlow unless flow
      end
      RUBY

      private_constant :ClassMethods, :CONSTRUCTOR

      # Deprecated: Classes with flows are now defined via `Micro::Case` inheritance
      def self.included(base)
        warn 'Deprecation: Micro::Case::Flow mixin is being deprecated, please use `Micro::Case` inheritance instead.'

        def base.flow_reducer; Reducer; end

        base.extend(ClassMethods)

        base.class_eval(CONSTRUCTOR)
      end

      def call
        self.class.__flow__.call(@options)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
u-case-2.3.1 lib/micro/case/flow.rb
u-case-2.3.0 lib/micro/case/flow.rb
u-case-2.2.0 lib/micro/case/flow.rb
u-case-2.1.1 lib/micro/case/flow.rb
u-case-2.1.0 lib/micro/case/flow.rb