Sha256: 70b0a0f6c05618d4657f10e49a179a5845f9036018a56f0e79a883ec7492f14b

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

# encoding: utf-8

require 'pony'
require 'socket'

module Adhearsion
  class Reporter
    class EmailNotifier
      include Singleton

      def init
        Pony.options = Adhearsion::Reporter.config.email
      end

      def notify(ex)
        Pony.mail({
          subject: email_subject(ex),
          body: exception_text(ex),
          from: hostname
        })
      end

      def self.method_missing(m, *args, &block)
        instance.send m, *args, &block
      end

    private
      def email_subject(exception)
        "[#{Adhearsion::Reporter.config.app_name}-#{environment}] Exception: #{exception.class} (#{exception.message})"
      end

      def exception_text(exception)
        backtrace = exception.backtrace || ["EMPTY BACKTRACE"]
        "#{Adhearsion::Reporter.config.app_name} reported an exception at #{Time.now.to_s}" +
        "\n\n#{exception.class} (#{exception.message}):\n" +
        backtrace.join("\n") +
        "\n\n"
      end

      def environment
        Adhearsion.config.platform.environment.to_s.upcase
      end

      def hostname
        Socket.gethostname
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
adhearsion-reporter-2.3.1 lib/adhearsion/reporter/email_notifier.rb
adhearsion-reporter-2.3.0 lib/adhearsion/reporter/email_notifier.rb
adhearsion-reporter-2.2.0 lib/adhearsion/reporter/email_notifier.rb