Class: Decouplio::Action
- Inherits:
-
Object
- Object
- Decouplio::Action
- Defined in:
- lib/decouplio/action.rb
Class Attribute Summary collapse
-
.meta_store ⇒ Object
Returns the value of attribute meta_store.
Instance Attribute Summary collapse
-
#ctx ⇒ Object
readonly
Returns the value of attribute ctx.
-
#meta_store ⇒ Object
(also: #ms)
readonly
Returns the value of attribute meta_store.
-
#railway_flow ⇒ Object
readonly
Returns the value of attribute railway_flow.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #append_railway_flow(stp) ⇒ Object
- #fail_action ⇒ Object
- #failure? ⇒ Boolean
-
#initialize(parent_railway_flow: nil, parent_ctx: nil, meta_store:, **params) ⇒ Action
constructor
A new instance of Action.
- #inspect ⇒ Object
- #pass_action ⇒ Object
- #success? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(parent_railway_flow: nil, parent_ctx: nil, meta_store:, **params) ⇒ Action
Returns a new instance of Action.
19 20 21 22 23 24 25 26 |
# File 'lib/decouplio/action.rb', line 19 def initialize( parent_railway_flow: nil, parent_ctx: nil, meta_store:, **params ) @meta_store = @ctx = parent_ctx || params @railway_flow = parent_railway_flow || [] @failure = false end |
Class Attribute Details
.meta_store ⇒ Object
Returns the value of attribute meta_store.
61 62 63 |
# File 'lib/decouplio/action.rb', line 61 def @meta_store end |
Instance Attribute Details
#ctx ⇒ Object (readonly)
Returns the value of attribute ctx.
15 16 17 |
# File 'lib/decouplio/action.rb', line 15 def ctx @ctx end |
#meta_store ⇒ Object (readonly) Also known as: ms
Returns the value of attribute meta_store.
15 16 17 |
# File 'lib/decouplio/action.rb', line 15 def @meta_store end |
#railway_flow ⇒ Object (readonly)
Returns the value of attribute railway_flow.
15 16 17 |
# File 'lib/decouplio/action.rb', line 15 def railway_flow @railway_flow end |
Class Method Details
.call(**params) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/decouplio/action.rb', line 67 def call(**params) instance = new( **{ meta_store: .new }.merge(**params) ) Decouplio::Processor.call(instance: instance, **@flow) instance end |
.call!(**params) ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/decouplio/action.rb', line 77 def call!(**params) instance = call(**params) if instance.failure? raise Decouplio::Errors::ExecutionError.new( action: instance ) else instance end end |
.meta_store_class(klass) ⇒ Object
63 64 65 |
# File 'lib/decouplio/action.rb', line 63 def (klass) self. = klass end |
Instance Method Details
#[](key) ⇒ Object
28 29 30 |
# File 'lib/decouplio/action.rb', line 28 def [](key) @ctx[key] end |
#append_railway_flow(stp) ⇒ Object
48 49 50 |
# File 'lib/decouplio/action.rb', line 48 def append_railway_flow(stp) railway_flow << stp end |
#fail_action ⇒ Object
40 41 42 |
# File 'lib/decouplio/action.rb', line 40 def fail_action @failure = true end |
#failure? ⇒ Boolean
36 37 38 |
# File 'lib/decouplio/action.rb', line 36 def failure? @failure end |
#inspect ⇒ Object
52 53 54 |
# File 'lib/decouplio/action.rb', line 52 def inspect Decouplio::ActionStatePrinter.call(self) end |
#pass_action ⇒ Object
44 45 46 |
# File 'lib/decouplio/action.rb', line 44 def pass_action @failure = false end |
#success? ⇒ Boolean
32 33 34 |
# File 'lib/decouplio/action.rb', line 32 def success? !@failure end |
#to_s ⇒ Object
56 57 58 |
# File 'lib/decouplio/action.rb', line 56 def to_s inspect end |