Class: DeviseSlackNotifiable::Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/devise_slack_notifiable/notifier.rb

Overview

Module <-> Slack communication layer and payload builder

Instance Method Summary collapse

Constructor Details

#initializeNotifier

DeviseSlackNotifiable::Notifier constructor.

Creates Slack::Notifier instance



13
14
15
16
17
18
19
# File 'lib/devise_slack_notifiable/notifier.rb', line 13

def initialize
  return unless enabled?

  raise DeviseSlackNotifiable::Errors::Configuration, 'Missing Slack Webhook URL' unless webhook

  @client = Slack::Notifier.new(webhook)
end

Instance Method Details

#send_message(entity, message_formatter) ⇒ Object

Sends slack message

Parameters:

  • entity (Model)
  • message_formatter (Proc)


25
26
27
28
29
30
31
32
33
34
# File 'lib/devise_slack_notifiable/notifier.rb', line 25

def send_message(entity, message_formatter)
  return true unless enabled?

  @client.ping(
    formatter(
      message_formatter.call(entity),
      entity
    )
  )
end