class Patches::Notifier

Public Class Methods

environment_prefix() click to toggle source
# File lib/patches/notifier.rb, line 30
def environment_prefix
  Rails.env.upcase if defined?(Rails)
end
failure_message(patch_path, error) click to toggle source
# File lib/patches/notifier.rb, line 17
def failure_message(patch_path, error)
  message("Error applying patch:", Pathname.new(patch_path).basename, "failed with error:", error)
end
message(*args) click to toggle source
# File lib/patches/notifier.rb, line 21
def message(*args)
  [notification_prefix, *args, notification_suffix].compact.join(" ")
end
notification_prefix() click to toggle source
# File lib/patches/notifier.rb, line 25
def notification_prefix
  prefix = config.notification_prefix.presence || environment_prefix
  "[#{prefix}]" if prefix.present?
end
notification_suffix() click to toggle source
# File lib/patches/notifier.rb, line 34
def notification_suffix
  config.notification_suffix.presence || tenant_suffix
end
notify_failure(patch_path, error) click to toggle source
# File lib/patches/notifier.rb, line 9
def notify_failure(patch_path, error)
  send_slack_message(failure_message(patch_path, error), 'danger')
end
notify_success(patches) click to toggle source
# File lib/patches/notifier.rb, line 5
def notify_success(patches)
  send_slack_message(success_message(patches), 'good')
end
send_slack_message(message, color) click to toggle source
# File lib/patches/notifier.rb, line 42
def send_slack_message(message, color)
  return unless defined?(Slack) && config.use_slack

  notifier = Slack::Notifier.new(
    config.slack_webhook_url,
    channel: config.slack_channel,
    username: config.slack_username)

  payload = { icon_emoji: ":dog:", attachments: [{ color: color, text: message }] }

  notifier.post payload
end
success_message(patches) click to toggle source
# File lib/patches/notifier.rb, line 13
def success_message(patches)
  message(patches.count, "patches succeeded")
end
tenant_suffix() click to toggle source
# File lib/patches/notifier.rb, line 38
def tenant_suffix
  "for tenant: #{Apartment::Tenant.current}" if defined?(Apartment)
end

Private Class Methods

config() click to toggle source
# File lib/patches/notifier.rb, line 57
def config
  Patches::Config.configuration
end