Class: Dispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/dispatcher.rb

Direct Known Subclasses

LinearDispatcher, ParallelDispatcher

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.deliver_new_cart_emails(cart) ⇒ Object


47
48
49
50
# File 'lib/dispatcher.rb', line 47

def self.deliver_new_cart_emails(cart)
  dispatcher = self.initialize_dispatcher(cart)
  dispatcher.deliver_new_cart_emails(cart)
end

.initialize_dispatcher(cart) ⇒ Object


34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/dispatcher.rb', line 34

def self.initialize_dispatcher(cart)
  case cart.flow
  when 'parallel'
    ParallelDispatcher.new
  when 'linear'
    if cart.ncr?
      NcrDispatcher.new
    else
      LinearDispatcher.new
    end
  end
end

.on_approval_status_change(approval) ⇒ Object


52
53
54
55
# File 'lib/dispatcher.rb', line 52

def self.on_approval_status_change(approval)
  dispatcher = self.initialize_dispatcher(approval.cart)
  dispatcher.on_approval_status_change(approval)
end

Instance Method Details

#deliver_new_cart_emails(cart) ⇒ Object


17
18
19
20
# File 'lib/dispatcher.rb', line 17

def deliver_new_cart_emails(cart)
  self.email_observers(cart)
  self.email_sent_confirmation(cart)
end

#email_approver(approval) ⇒ Object


2
3
4
5
# File 'lib/dispatcher.rb', line 2

def email_approver(approval)
  approval.create_api_token!
  send_notification_email(approval)
end

#email_observers(cart) ⇒ Object


7
8
9
10
11
# File 'lib/dispatcher.rb', line 7

def email_observers(cart)
  cart.approvals.where(role: 'observer').each do |observer|
    CommunicartMailer.cart_observer_email(observer.user_email_address, cart).deliver
  end
end

#email_sent_confirmation(cart) ⇒ Object


13
14
15
# File 'lib/dispatcher.rb', line 13

def email_sent_confirmation(cart)
  CommunicartMailer.proposal_created_confirmation(cart).deliver
end

#on_approval_status_change(approval) ⇒ Object


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

def on_approval_status_change(approval)
  if self.requires_approval_notice?(approval) || approval.status == 'rejected'
    CommunicartMailer.approval_reply_received_email(approval).deliver
  end

  self.email_observers(approval.cart)
end

#requires_approval_notice?(approval) ⇒ Boolean

Returns:

  • (Boolean)

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

def requires_approval_notice?(approval)
  true
end