Class: ESM::Event::SendXm8Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/esm/event/send_xm8_notification.rb,
lib/esm/event/send_xm8_notification/notification_manager.rb

Defined Under Namespace

Classes: NotificationManager

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, message) ⇒ SendXm8Notification

Returns a new instance of SendXm8Notification.



20
21
22
23
24
# File 'lib/esm/event/send_xm8_notification.rb', line 20

def initialize(server, message)
  @server = server
  @community = server.community
  @message = message
end

Instance Attribute Details

#communityObject (readonly)

Returns the value of attribute community.



18
19
20
# File 'lib/esm/event/send_xm8_notification.rb', line 18

def community
  @community
end

#messageObject (readonly)

Returns the value of attribute message.



18
19
20
# File 'lib/esm/event/send_xm8_notification.rb', line 18

def message
  @message
end

#serverObject (readonly)

Returns the value of attribute server.



18
19
20
# File 'lib/esm/event/send_xm8_notification.rb', line 18

def server
  @server
end

Class Method Details

.notification_managerObject



6
7
8
# File 'lib/esm/event/send_xm8_notification.rb', line 6

def self.notification_manager
  @notification_manager ||= NotificationManager.new
end

.send_notifications(notifications) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/esm/event/send_xm8_notification.rb', line 10

def self.send_notifications(notifications)
  if notifications.any? { |n| !n.is_a?(Xm8Notification) }
    raise TypeError, "Invalid notifications provided: #{notifications}"
  end

  notification_manager.add(notifications)
end

Instance Method Details

#run!Object



26
27
28
29
30
31
# File 'lib/esm/event/send_xm8_notification.rb', line 26

def run!
  notifications = filter_notifications
  return if notifications.blank?

  self.class.send_notifications(notifications)
end