Sha256: 0f63b795d7cf6d2a7d1576242dca0cbfe2dfa0fc837d8c8424ed3712feab167a
Contents?: true
Size: 1.26 KB
Versions: 1
Compression:
Stored size: 1.26 KB
Contents
module DirtyPipeline class Transition def Abort() throw :abort, true end def Error(error) throw :fail_with_error, error end def Success(changes = nil) throw :success, changes.to_h end def self.finalize(*args, **kwargs) event, pipeline, *args = args instance = new(event, *args, **kwargs) pipeline.railway.switch_to(:call) return unless instance.respond_to?(:finalize) instance.finalize(pipeline.subject) end def self.undo(*args, **kwargs) event, pipeline, *args = args instance = new(event, *args, **kwargs) return unless instance.respond_to?(:undo) instance.undo(pipeline.subject) end def self.call(*args, **kwargs) event, pipeline, *args = args instance = new(event, *args, **kwargs) pipeline.railway[:undo] << event if instance.respond_to?(:undo) pipeline.railway[:finalize] << event if instance.respond_to?(:finalize) pipeline.railway.switch_to(:finalize) if instance.respond_to?(:finalize) new(event, *args, **kwargs).call(pipeline.subject) end attr_reader :event def initialize(event, *, **) @event = event end def fetch(key) event.cache.fetch(key) { event.cache[key] = yield } end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
dirty_pipeline-0.5.0 | lib/dirty_pipeline/transition.rb |