Sha256: 4a4087f04131ffbc49679e3e9bc3ad5ab3816d4cbe33f5a125ca114535755554

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

module Micro
  module Service
    module Pipeline
      module ClassMethods
        def __pipeline__
          @__pipeline
        end

        def pipeline(*args)
          @__pipeline = pipeline_reducer.build(args)
        end

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

      CONSTRUCTOR = <<-RUBY
      def initialize(options)
        @options = options
        pipeline = self.class.__pipeline__
        raise Error::UndefinedPipeline unless pipeline
      end
      RUBY

      private_constant :ClassMethods, :CONSTRUCTOR

      def self.included(base)
        def base.pipeline_reducer; Reducer; end
        base.extend(ClassMethods)
        base.class_eval(CONSTRUCTOR)
      end

      def self.[](*args)
        Reducer.build(args)
      end

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

      module Safe
        def self.included(base)
          base.send(:include, Micro::Service::Pipeline)
          def base.pipeline_reducer; SafeReducer; end
        end

        def self.[](*args)
          SafeReducer.build(args)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
u-service-1.0.0 lib/micro/service/pipeline.rb