Class: Alerter::MessageDispatcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, recipients) ⇒ MessageDispatcher

Returns a new instance of MessageDispatcher.



12
13
14
# File 'lib/alerter/message_dispatcher.rb', line 12

def initialize(message, recipients)
  @message, @recipients = message, recipients
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



10
11
12
# File 'lib/alerter/message_dispatcher.rb', line 10

def message
  @message
end

#recipientsObject (readonly)

Returns the value of attribute recipients.



10
11
12
# File 'lib/alerter/message_dispatcher.rb', line 10

def recipients
  @recipients
end

Instance Method Details

#callObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/alerter/message_dispatcher.rb', line 16

def call
  return false unless (Alerter.notification_method - Alerter.available_notification_methods).empty? # array subtraction to see if notification methods are in the available list
  Alerter.notification_method.each do |method|
    case method
      when 'email'
        if Alerter.mailer_wants_array
          send_email(filtered_recipients(method))
        else
          filtered_recipients(method).each do |recipient|
            send_email(recipient) if recipient.notification_methods(message.notification_type).include?(method) && recipient.email.present?
          end
        end
      when 'none', 'ios_push', 'android_push', 'sms', 'twitter'

      else
        raise MethodNotImplemented.new(method)
    end
  end
end