Sha256: a704488b2ffd19c6cdd40338c51cd66729c994e4d82046f74fe8caf2d6650bf1

Contents?: true

Size: 972 Bytes

Versions: 4

Compression:

Stored size: 972 Bytes

Contents

# frozen_string_literal: true

require 'business_pipeline/config'
require 'business_pipeline/context'
require 'business_pipeline/hooks'

module BusinessPipeline
  module Step
    def self.included(base)
      base.class_eval do
        include Hooks

        attr_reader :context
        private :context

        attr_reader :config
        private :config

        def self.inherited(child_class)
          child_class.instance_variable_set(:@hooks, hooks.clone)
        end
      end
    end

    def initialize(config = {})
      @config = BusinessPipeline::Config.new(config)
    end

    def call
      fail NotImplementedError
    end

    def fail!(additional_context = {})
      context.fail!(additional_context)
    end

    def perform(context = {})
      @context = BusinessPipeline::Context.build(context)
      with_hooks { call }
      @context
    end

    def succeed!(additional_context = {})
      context.succeed!(additional_context)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
business_pipeline-0.3.1 lib/business_pipeline/step.rb
business_pipeline-0.3.0 lib/business_pipeline/step.rb
business_pipeline-0.2.0 lib/business_pipeline/step.rb
business_pipeline-0.1.3 lib/business_pipeline/step.rb