Class: DirtyPipeline::Transition
- Inherits:
-
Object
- Object
- DirtyPipeline::Transition
- Defined in:
- lib/dirty_pipeline/transition.rb
Instance Attribute Summary collapse
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#railway ⇒ Object
readonly
Returns the value of attribute railway.
Class Method Summary collapse
Instance Method Summary collapse
- #cache(key) ⇒ Object
- #Failure(error) ⇒ Object
-
#initialize(event, railway) ⇒ Transition
constructor
A new instance of Transition.
- #Success(changes = nil) ⇒ Object
Constructor Details
#initialize(event, railway) ⇒ Transition
Returns a new instance of Transition.
41 42 43 44 |
# File 'lib/dirty_pipeline/transition.rb', line 41 def initialize(event, railway, *, **) @event = event @railway = railway end |
Instance Attribute Details
#event ⇒ Object (readonly)
Returns the value of attribute event.
40 41 42 |
# File 'lib/dirty_pipeline/transition.rb', line 40 def event @event end |
#railway ⇒ Object (readonly)
Returns the value of attribute railway.
40 41 42 |
# File 'lib/dirty_pipeline/transition.rb', line 40 def railway @railway end |
Class Method Details
.call(*args, **kwargs) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/dirty_pipeline/transition.rb', line 32 def self.call(*args, **kwargs) event, pipeline, *args = args instance = new(event, pipeline.railway, *args, **kwargs) pipeline&.railway&.send(:[], :undo)&.send(:<<, event) pipeline&.railway&.send(:[], :finalize)&.send(:<<, event) instance.call(pipeline.subject) end |
.finalize(*args, **kwargs) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/dirty_pipeline/transition.rb', line 18 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 |
.undo(*args, **kwargs) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/dirty_pipeline/transition.rb', line 25 def self.undo(*args, **kwargs) event, pipeline, *args = args instance = new(event, pipeline.railway, *args, **kwargs) return unless instance.respond_to?(:undo) instance.undo(pipeline.subject) end |
Instance Method Details
#cache(key) ⇒ Object
46 47 48 |
# File 'lib/dirty_pipeline/transition.rb', line 46 def cache(key) event.cache.fetch(key) { event.cache[key] = yield } end |
#Failure(error) ⇒ Object
3 4 5 6 |
# File 'lib/dirty_pipeline/transition.rb', line 3 def Failure(error) railway&.switch_to(:undo) throw :fail_transition, error end |
#Success(changes = nil) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/dirty_pipeline/transition.rb', line 8 def Success(changes = nil) case railway&.active when "call" railway&.switch_to(:finalize) if respond_to?(:finalize) when "finalize" railway&.switch_to(:call) end throw :success, changes.to_h end |