class ExceptionNotifier::SlackNotifier
Attributes
notifier[RW]
Public Class Methods
new(options)
click to toggle source
# File lib/support/exception_slack_notify/exception_notification.rb, line 12 def initialize(options) begin webhook_url = options.fetch(:webhook_url) @message_opts = options.fetch(:additional_parameters, {}) @notifier = Slack::Notifier.new webhook_url, options rescue @notifier = nil end end
Public Instance Methods
call(exception, options={})
click to toggle source
# File lib/support/exception_slack_notify/exception_notification.rb, line 22 def call(exception, options={}) message = [ "时间: #{ Time.now.to_s }", "URL: #{ options[:env]["REQUEST_URI"] }", "参数: #{ options[:env]["action_dispatch.request.parameters"] }", "用户IP: #{ options[:env]["action_dispatch.remote_ip"] }", "异常: #{ [exception.message, exception.backtrace].flatten.join("\n") }", "===============================================" ].join("\n\n") @notifier.ping(message, @message_opts) if valid? end
Protected Instance Methods
valid?()
click to toggle source
# File lib/support/exception_slack_notify/exception_notification.rb, line 37 def valid? !@notifier.nil? end