lib/dirty_pipeline/status.rb in dirty_pipeline-0.4.0 vs lib/dirty_pipeline/status.rb in dirty_pipeline-0.5.0

- old
+ new

@@ -1,55 +1,27 @@ module DirtyPipeline - class Status < SimpleDelegator - attr_accessor :error, :succeeded, :action_pool - attr_reader :storage, :pipeline - def initialize(*) - super - @storage = __getobj__.storage - @action_pool = [] - end + class Status + attr_reader :success, :tag, :data - def wrap - return self if succeeded == false - self.succeeded = nil - yield - self + def self.success(data, tag: :success) + new(true, data, tag) end - def success? - !!succeeded + def self.failure(data, tag: :exception) + new(false, data, tag) end - def when_success(callback = nil) - return self unless success? - block_given? ? yield(self) : callback.(self) - self + def initialize(success, data, tag = nil) + @success = success + @data = data + @tag = tag end - def when_failed(callback = nil) - return self unless storage.failed? - block_given? ? yield(self) : callback.(self) - self + def success? + !!success 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 + def failure? + !success? end end end