21
1
Fork 0
mirror of https://github.com/Evolix/chexpire.git synced 2024-04-29 23:40:49 +02:00
chexpire/app/services/notifier/channels/base.rb
2018-06-04 14:18:12 +02:00

42 lines
1.2 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)
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
# domain notifications
def domain_notify_expires_soon(_notification)
fail NotImplementedError,
"Channel #{self.class.name} does not implement #{__callee__}"
end
def domain_notify_recurrent_failures(_notification)
fail NotImplementedError,
"Channel #{self.class.name} does not implement #{__callee__}"
end
# :nocov:
end
end
end