Class: MocaRlibs::SlackNotifier
- Inherits:
-
Object
- Object
- MocaRlibs::SlackNotifier
- Defined in:
- lib/moca_rlibs/slack_notifier.rb
Overview
Slack通知クライアント
Constant Summary collapse
- SLACK_WEBHOOK_URL =
ENV["#{PREFIX}_SLACK_WEBHOOK_URL"]
- SLACK_DEFAULT_CHANNEL =
ENV["#{PREFIX}_SLACK_DEFAULT_CHANNEL"]
- SLACK_DEFAULT_USER =
ENV["#{PREFIX}_SLACK_DEFAULT_USER"]
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Class Method Summary collapse
-
.error(err, channel: nil, username: nil, webhook: nil) ⇒ Object
エラーログを送信.
-
.send(message, channel: nil, username: nil, webhook: nil, at: nil) ⇒ Object
シンプルなテキストを送信する.
Instance Method Summary collapse
-
#error(err) ⇒ Object
エラーログを送信.
-
#initialize(webhook: nil, channel: nil, username: nil) ⇒ SlackNotifier
constructor
A new instance of SlackNotifier.
-
#send(message, at: nil) ⇒ Object
シンプルなテキストを送信する.
Constructor Details
#initialize(webhook: nil, channel: nil, username: nil) ⇒ SlackNotifier
Returns a new instance of SlackNotifier.
23 24 25 26 27 28 29 |
# File 'lib/moca_rlibs/slack_notifier.rb', line 23 def initialize(webhook: nil, channel: nil, username: nil) @client = Slack::Notifier.new( webhook || SLACK_WEBHOOK_URL, channel: channel || SLACK_DEFAULT_CHANNEL, username: username || SLACK_DEFAULT_USER ) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
14 15 16 |
# File 'lib/moca_rlibs/slack_notifier.rb', line 14 def client @client end |
Class Method Details
.error(err, channel: nil, username: nil, webhook: nil) ⇒ Object
エラーログを送信
64 65 66 67 68 |
# File 'lib/moca_rlibs/slack_notifier.rb', line 64 def self.error(err, channel: nil, username: nil, webhook: nil) backtrace = (err.backtrace&.join || 'no backtrace info').sub('`', '\'').slice(0, 2000) new(webhook: webhook, channel: channel, username: username) .send("#{err.}\n```\n#{backtrace}\n```", at: 'here') end |
.send(message, channel: nil, username: nil, webhook: nil, at: nil) ⇒ Object
シンプルなテキストを送信する
53 54 55 56 |
# File 'lib/moca_rlibs/slack_notifier.rb', line 53 def self.send(, channel: nil, username: nil, webhook: nil, at: nil) new(webhook: webhook, channel: channel, username: username) .send(, at: at) end |
Instance Method Details
#error(err) ⇒ Object
エラーログを送信
42 43 44 |
# File 'lib/moca_rlibs/slack_notifier.rb', line 42 def error(err) send("#{err.}\n```#{err.backtrace}```", at: 'here') end |
#send(message, at: nil) ⇒ Object
シンプルなテキストを送信する
35 36 37 |
# File 'lib/moca_rlibs/slack_notifier.rb', line 35 def send(, at: nil) @client.ping("#{at ? "<!#{at}> " : ''}#{}") end |