Class: Services::Notifiers::StationEventNotifier Abstract

Inherits:
Object
  • Object
show all
Defined in:
app/services/notifiers/station_event_notifier.rb

Overview

This class is abstract.

Used to constuct notifiers

Direct Known Subclasses

LowBalance, StationOffline, StationOnline

Class Method Summary collapse

Class Method Details

.call(station) ⇒ Void



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/services/notifiers/station_event_notifier.rb', line 24

def self.call(station)
  msg = self.message(station)
  Rails.logger.info(msg)
  notified = Notification
                 .where(message: msg)
                 .since(12.hours.ago)
                 .count > 0
  unless notified
    mail = StationMailer.send(self.mailer_method, station)
    mail.deliver_now
    Notification.create!(
        user: station.user,
        level: self.level,
        message: msg,
        event: self.event
    )
  end
end

.eventObject



10
11
12
# File 'app/services/notifiers/station_event_notifier.rb', line 10

def self.event
  raise NotImplementedError not_impemented_msg(__method__)
end

.levelObject



14
15
16
# File 'app/services/notifiers/station_event_notifier.rb', line 14

def self.level
  :info
end

.mailer_methodObject



18
19
20
# File 'app/services/notifiers/station_event_notifier.rb', line 18

def self.mailer_method
  event.sub("station_", '').to_sym
end

.message(station) ⇒ Object



6
7
8
# File 'app/services/notifiers/station_event_notifier.rb', line 6

def self.message(station)
  raise NotImplementedError not_impemented_msg(__method__)
end