Class: Ni::Flows::BranchInteractor

Inherits:
Base
  • Object
show all
Includes:
Utils::HandleWait
Defined in:
lib/ni/flows/branch_interactor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options, &block)
  if options[:when].blank? || !options[:when].is_a?(Proc)
    raise "Can't build brunch without a condition"
  else
    self.condition = options[: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

#actionObject

Returns the value of attribute action.



5
6
7
# File 'lib/ni/flows/branch_interactor.rb', line 5

def action
  @action
end

#conditionObject

Returns the value of attribute condition.



5
6
7
# File 'lib/ni/flows/branch_interactor.rb', line 5

def condition
  @condition
end

#interactor_klassObject

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

Returns:

  • (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