Class: ExceptionNotifier::LarkNotifier
- Inherits:
-
Object
- Object
- ExceptionNotifier::LarkNotifier
- Includes:
- BacktraceCleaner
- Defined in:
- lib/exception_notifier/lark_notifier.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call(exception, call_options = {}) ⇒ Object
-
#initialize(options) ⇒ LarkNotifier
constructor
A new instance of LarkNotifier.
Constructor Details
#initialize(options) ⇒ LarkNotifier
Returns a new instance of LarkNotifier.
21 22 23 24 25 26 27 28 29 |
# File 'lib/exception_notifier/lark_notifier.rb', line 21 def initialize() @default_app_name = self.class.rails_app_name @default_env_name = self.class.rails_env_name @default_options = @notifier = ExceptionNotificationLarkNotifier::Client.new( .slice(:webhook_url, :webhook_secret, :http) ) end |
Class Method Details
.rails_app_name ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/exception_notifier/lark_notifier.rb', line 6 def rails_app_name return unless defined?(::Rails) && ::Rails.respond_to?(:application) if ::Gem::Version.new(::Rails.version) >= ::Gem::Version.new("6.0") ::Rails.application.class.module_parent_name else ::Rails.application.class.parent_name end end |
.rails_env_name ⇒ Object
15 16 17 18 |
# File 'lib/exception_notifier/lark_notifier.rb', line 15 def rails_env_name return unless defined?(::Rails) && ::Rails.respond_to?(:env) ::Rails.env end |
Instance Method Details
#call(exception, call_options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/exception_notifier/lark_notifier.rb', line 31 def call(exception, = {}) = .merge(@default_options) app_name = .delete(:app_name) || @default_app_name env_name = .delete(:env_name) || @default_env_name title = "Exception Occurred" title += " in #{app_name}" if app_name title += " (env: #{env_name})" if env_name backtrace = exception.backtrace ? clean_backtrace(exception) : [] summary, data = (exception.class, ) fields = fields(exception., backtrace, data) @notifier.post interactive: { header: { title: {tag: "plain_text", content: title} }, elements: [{ tag: "div", text: {tag: "lark_md", content: summary}, fields: fields }] } end |