Sha256: 4eb6c6081bab4389dd5de1e3efdc6e76cd6252674dba1b9f8e9864ab6a28c972

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module Micro
  class Case
    module Flow
      module ClassMethods
        def __flow__
          return @__flow if defined?(@__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

3 entries across 3 versions & 1 rubygems

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