Class: Patches::Notifier
- Inherits:
-
Object
- Object
- Patches::Notifier
- Defined in:
- lib/patches/notifier.rb
Class Method Summary collapse
- .environment_prefix ⇒ Object
- .failure_message(patch_path, error) ⇒ Object
- .message(*args) ⇒ Object
- .notification_prefix ⇒ Object
- .notification_suffix ⇒ Object
- .notify_failure(patch_path, error) ⇒ Object
- .notify_success(patches) ⇒ Object
- .send_slack_message(message, color) ⇒ Object
- .success_message(patches) ⇒ Object
- .tenant_suffix ⇒ Object
Class Method Details
.environment_prefix ⇒ Object
30 31 32 |
# File 'lib/patches/notifier.rb', line 30 def environment_prefix Rails.env.upcase if defined?(Rails) end |
.failure_message(patch_path, error) ⇒ Object
17 18 19 |
# File 'lib/patches/notifier.rb', line 17 def (patch_path, error) ("Error applying patch:", Pathname.new(patch_path).basename, "failed with error:", error) end |
.message(*args) ⇒ Object
21 22 23 |
# File 'lib/patches/notifier.rb', line 21 def (*args) [notification_prefix, *args, notification_suffix].compact.join(" ") end |
.notification_prefix ⇒ Object
25 26 27 28 |
# File 'lib/patches/notifier.rb', line 25 def notification_prefix prefix = config.notification_prefix.presence || environment_prefix "[#{prefix}]" if prefix.present? end |
.notification_suffix ⇒ Object
34 35 36 |
# File 'lib/patches/notifier.rb', line 34 def notification_suffix config.notification_suffix.presence || tenant_suffix end |
.notify_failure(patch_path, error) ⇒ Object
9 10 11 |
# File 'lib/patches/notifier.rb', line 9 def notify_failure(patch_path, error) ((patch_path, error), 'danger') end |
.notify_success(patches) ⇒ Object
5 6 7 |
# File 'lib/patches/notifier.rb', line 5 def notify_success(patches) ((patches), 'good') end |
.send_slack_message(message, color) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/patches/notifier.rb', line 42 def (, 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: }] } notifier.post payload end |
.success_message(patches) ⇒ Object
13 14 15 |
# File 'lib/patches/notifier.rb', line 13 def (patches) (patches.count, "patches succeeded") end |
.tenant_suffix ⇒ Object
38 39 40 |
# File 'lib/patches/notifier.rb', line 38 def tenant_suffix "for tenant: #{Apartment::Tenant.current}" if defined?(Apartment) end |