Sha256: 4eb772c01dc01c3d5b453628a46b13c6b29160de6949edfc845474ce6595c93f

Contents?: true

Size: 935 Bytes

Versions: 2

Compression:

Stored size: 935 Bytes

Contents

module DirtyPipeline
  class Transition
    def Abort()
      throw :abort, true
    end

    def Error(error)
      throw :fail_with_error, error
    end

    def Success(output = nil, after_commit: nil, &block)
      result = [output.to_h]
      after_commit = Array(after_commit) << block if block_given?
      result += Array(after_commit) if after_commit
      throw :success, result
    end

    def self.undo(*args, **kwargs)
      pipeline = args.shift
      instance = new(pipeline, *args, **kwargs)
      return unless instance.respond_to?(:undo)
      instance.undo(pipeline.subject)
    end

    def self.call(*args, **kwargs)
      pipeline = args.shift
      new(pipeline, *args, **kwargs).call(pipeline.subject)
    end

    attr_reader :pipeline
    def initialize(pipeline, *, **)
      @pipeline = pipeline
    end

    def fetch(key)
      pipeline.cache.fetch(key) { pipeline.cache[key] = yield }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dirty_pipeline-0.4.0 lib/dirty_pipeline/transition.rb
dirty_pipeline-0.3.0 lib/dirty_pipeline/transition.rb