Class: Ni::Flows::BranchInteractor
- Includes:
- Utils::HandleWait
- Defined in:
- lib/ni/flows/branch_interactor.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#interactor_klass ⇒ Object
Returns the value of attribute interactor_klass.
Instance Method Summary collapse
- #call(context, params = {}) ⇒ Object
- #call_for_wait_continue(context, params = {}) ⇒ Object
- #handle_current_wait?(context, name) ⇒ Boolean
-
#initialize(top_level_interactor_klass, args, options, &block) ⇒ BranchInteractor
constructor
A new instance of BranchInteractor.
Constructor Details
#initialize(top_level_interactor_klass, args, options, &block) ⇒ BranchInteractor
Returns a new instance of BranchInteractor.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ni/flows/branch_interactor.rb', line 7 def initialize(top_level_interactor_klass, args, , &block) if [:when].blank? || ![:when].is_a?(Proc) raise "Can't build brunch without a condition" else self.condition = [:when] end if args.size == 2 interactor_klass, action = args else id_or_interactor = args.first action = :perform if id_or_interactor.is_a?(Symbol) interactor_klass = build_anonymous_interactor(top_level_interactor_klass, id_or_interactor, &block) else interactor_klass = id_or_interactor end end self.interactor_klass, self.action = interactor_klass, action end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
5 6 7 |
# File 'lib/ni/flows/branch_interactor.rb', line 5 def action @action end |
#condition ⇒ Object
Returns the value of attribute condition.
5 6 7 |
# File 'lib/ni/flows/branch_interactor.rb', line 5 def condition @condition end |
#interactor_klass ⇒ Object
Returns the value of attribute interactor_klass.
5 6 7 |
# File 'lib/ni/flows/branch_interactor.rb', line 5 def interactor_klass @interactor_klass end |
Instance Method Details
#call(context, params = {}) ⇒ Object
30 31 32 33 34 |
# File 'lib/ni/flows/branch_interactor.rb', line 30 def call(context, params={}) return unless self.condition.call(context) run(context, params) end |
#call_for_wait_continue(context, params = {}) ⇒ Object
36 37 38 |
# File 'lib/ni/flows/branch_interactor.rb', line 36 def call_for_wait_continue(context, params={}) call(context, params) end |
#handle_current_wait?(context, name) ⇒ Boolean
40 41 42 |
# File 'lib/ni/flows/branch_interactor.rb', line 40 def handle_current_wait?(context, name) self.condition.call(context) && super end |