class DirtyPipeline::Transition
Attributes
event[R]
railway[R]
Public Class Methods
call(*args, **kwargs)
click to toggle source
# File lib/dirty_pipeline/transition.rb, line 46 def self.call(*args, **kwargs) event, pipeline, *args = args instance = new(event, pipeline.railway, *args, **kwargs) pipeline&.railway&.send(:[], :finalize)&.send(:<<, event) prepare_undo(pipeline, event) instance.call(pipeline.subject) end
finalize(*args, **kwargs)
click to toggle source
# File lib/dirty_pipeline/transition.rb, line 31 def self.finalize(*args, **kwargs) event, pipeline, *args = args instance = new(event, pipeline.railway, *args, **kwargs) return unless instance.respond_to?(:finalize) instance.finalize(pipeline.subject) end
finalize_undo(*args, **kwargs)
click to toggle source
# File lib/dirty_pipeline/transition.rb, line 24 def self.finalize_undo(*args, **kwargs) event, pipeline, *args = args instance = new(event, pipeline.railway, *args, **kwargs) return unless instance.respond_to?(:finalize_undo) instance.finalize_undo(pipeline.subject) end
new(event, railway, *, **)
click to toggle source
# File lib/dirty_pipeline/transition.rb, line 62 def initialize(event, railway, *, **) @event = event @railway = railway end
prepare_undo(pipeline, event)
click to toggle source
# File lib/dirty_pipeline/transition.rb, line 54 def self.prepare_undo(pipeline, event) anti_event = event.dup anti_event.source, anti_event.destination = event.destination, event.source pipeline&.railway&.send(:[], :undo)&.send(:unshift, anti_event) end
undo(*args, **kwargs)
click to toggle source
# File lib/dirty_pipeline/transition.rb, line 38 def self.undo(*args, **kwargs) event, pipeline, *args = args instance = new(event, pipeline.railway, *args, **kwargs) pipeline&.railway&.send(:[], :finalize_undo)&.send(:<<, event) return unless instance.respond_to?(:undo) instance.undo(pipeline.subject) end
Public Instance Methods
Failure(error)
click to toggle source
# File lib/dirty_pipeline/transition.rb, line 5 def Failure(error) railway&.switch_to(:undo) throw :fail_transition, error end
Success(changes = nil)
click to toggle source
# File lib/dirty_pipeline/transition.rb, line 10 def Success(changes = nil) case railway&.active when "finalize_undo" railway&.switch_to(:undo) when "undo" railway&.switch_to(:finalize_undo) if respond_to?(:finalize_undo) when "call" railway&.switch_to(:finalize) if respond_to?(:finalize) when "finalize" railway&.switch_to(:call) end throw :success, changes.to_h end
cache(key) { || ... }
click to toggle source
# File lib/dirty_pipeline/transition.rb, line 67 def cache(key) event.cache.fetch(key) { event.cache[key] = yield } end