Class: ExceptionNotifier::SlackNotifier
- Inherits:
-
Object
- Object
- ExceptionNotifier::SlackNotifier
- Defined in:
- lib/support/exception_slack_notify/exception_notification.rb
Instance Attribute Summary collapse
-
#notifier ⇒ Object
Returns the value of attribute notifier.
Instance Method Summary collapse
- #call(exception, options = {}) ⇒ Object
-
#initialize(options) ⇒ SlackNotifier
constructor
A new instance of SlackNotifier.
Constructor Details
#initialize(options) ⇒ SlackNotifier
Returns a new instance of SlackNotifier.
12 13 14 15 16 17 18 19 20 |
# File 'lib/support/exception_slack_notify/exception_notification.rb', line 12 def initialize() begin webhook_url = .fetch(:webhook_url) @message_opts = .fetch(:additional_parameters, {}) @notifier = Slack::Notifier.new webhook_url, rescue @notifier = nil end end |
Instance Attribute Details
#notifier ⇒ Object
Returns the value of attribute notifier.
10 11 12 |
# File 'lib/support/exception_slack_notify/exception_notification.rb', line 10 def notifier @notifier end |
Instance Method Details
#call(exception, options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/support/exception_slack_notify/exception_notification.rb', line 22 def call(exception, ={}) = [ "时间: #{ Time.now.to_s }", "URL: #{ [:env]["REQUEST_URI"] }", "参数: #{ [:env]["action_dispatch.request.parameters"] }", "用户IP: #{ [:env]["action_dispatch.remote_ip"] }", "异常: #{ [exception., exception.backtrace].flatten.join("\n") }", "===============================================" ].join("\n\n") @notifier.ping(, @message_opts) if valid? end |