Sha256: a9b099e66a4f05a341d9800af57d5aa1319cc9e945113c4308dbb316eec76d30
Contents?: true
Size: 1.2 KB
Versions: 2
Compression:
Stored size: 1.2 KB
Contents
module DirtyPipeline class Transition def Error(error) throw :fail_transition, 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) return unless instance.respond_to?(:finalize) pipeline.railway.switch_to(:call) 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) if instance.respond_to?(:finalize) pipeline.railway[:finalize] << event pipeline.railway.switch_to(:finalize) end 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dirty_pipeline-0.6.2 | lib/dirty_pipeline/transition.rb |
dirty_pipeline-0.6.1 | lib/dirty_pipeline/transition.rb |