21
1
Fork 0
mirror of https://github.com/Evolix/chexpire.git synced 2024-04-27 22:40:49 +02:00
chexpire/app/services/notifier/channels/base.rb
2018-07-02 18:40:09 +02:00

47 lines
1.4 KiB
Ruby

module Notifier
module Channels
class Base
def notify(reason, notification) # rubocop:disable Metrics/MethodLength
return unless supports?(reason, notification)
notification.ongoing!
case [notification.check.kind.to_sym, reason]
when [:domain, :expires_soon]
domain_notify_expires_soon(notification)
when [:domain, :recurrent_failures]
domain_notify_recurrent_failures(notification)
when [:ssl, :expires_soon]
ssl_notify_expires_soon(notification)
when [:ssl, :recurrent_failures]
ssl_notify_recurrent_failures(notification)
else
fail ArgumentError,
"Invalid notification reason `#{reason}` for check kind `#{notification.check.kind}`."
end
end
private
# :nocov:
def supports?(_reason, _notification)
fail NotImplementedError,
"#{self.class.name} channel did not implemented method #{__callee__}"
end
%i[
domain_notify_expires_soon
domain_notify_recurrent_failures
ssl_notify_expires_soon
ssl_notify_recurrent_failures
].each do |method|
define_method(method) do
fail NotImplementedError,
"Channel #{self.class.name} does not implement method #{method}."
end
end
# :nocov:
end
end
end