Module: Interactor::Organizer::InstanceMethods

Defined in:
lib/better_interactor/organizer.rb

Instance Method Summary collapse

Instance Method Details

#callObject

Internal: Invoke the organized Interactors. An Interactor::Organizer is expected not to define its own “#call” method in favor of this default implementation.

Returns nothing.



10
11
12
13
14
# File 'lib/better_interactor/organizer.rb', line 10

def call
  self.class.organized.each do |interactor|
    handle_call(interactor) if should_call? interactor
  end
end

#condition_for(interactor) ⇒ Object



30
31
32
# File 'lib/better_interactor/organizer.rb', line 30

def condition_for(interactor)
  interactor.is_a?(Symbol) ? "can_#{interactor}}?" : interactor.default_condition_name
end

#handle_call(interactor) ⇒ Object



16
17
18
19
# File 'lib/better_interactor/organizer.rb', line 16

def handle_call(interactor)
  to_call = interactor.is_a?(Hash) ? interactor[:class] : interactor
  to_call.is_a?(Symbol) ? send(to_call) : to_call.call!(context)
end

#should_call?(interactor) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
# File 'lib/better_interactor/organizer.rb', line 21

def should_call?(interactor)
  if interactor.is_a?(Hash)
    interactor[:if].nil? || send(interactor[:if])
  else
    condition = condition_for interactor
    !respond_to?(condition) || send(condition)
  end
end