Sha256: 540b1e12da1a5f2551e8d94812df88ce396f533283f360387969dae6cad24e74

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

module DirtyPipeline
  class Status < SimpleDelegator
    attr_accessor :error, :succeeded, :action_pool
    attr_reader :storage, :pipeline
    def initialize(*)
      super
      @storage = __getobj__.storage
      @action_pool = []
    end

    def wrap
      return self if succeeded == false
      self.succeeded = nil
      yield
      self
    end

    def success?
      !!succeeded
    end

    def when_success(callback = nil)
      return self unless success?
      block_given? ? yield(self) : callback.(self)
      self
    end

    def when_failed(callback = nil)
      return self unless storage.failed?
      block_given? ? yield(self) : callback.(self)
      self
    end

    def errored?
      return if succeeded.nil?
      ready? && !succeeded
    end

    def when_error(callback = nil)
      return self unless errored?
      block_given? ? yield(self) : callback.(self)
      self
    end

    def ready?
      storage.pipeline_status.nil?
    end

    def when_processing(callback = nil)
      return self unless storage.processing?
      block_given? ? yield(self) : callback.(self)
      self
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dirty_pipeline-0.4.0 lib/dirty_pipeline/status.rb