Sha256: 26ad88421e6207322178351cd9fba8c33b3811ab9f15ebe61a1fec4cc0028fc8

Contents?: true

Size: 1.29 KB

Versions: 3

Compression:

Stored size: 1.29 KB

Contents

module Chatterbox
  class EmailConsumer
    
    attr_reader :notice
    
    def initialize(notice)
      @notice = notice
    end
    
    def process
      Chatterbox.logger.debug { "Mailing notification #{notice[:summary]}"}
      Mailer.deliver_exception_notification(notice)
    end
  
  end
  
  class Mailer < ActionMailer::Base
    @@sender_address = %("Exception Notifier" <exception.notifier@default.com>)
    cattr_accessor :sender_address

    @@exception_recipients = []
    cattr_accessor :exception_recipients

    @@email_prefix = "[ERROR] "
    cattr_accessor :email_prefix

    self.template_root = File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. views]))

    def self.reloadable?() false end

    def exception_notification(data={})
      data = data.symbolize_keys
      
      content_type "text/plain"

      subject    "#{email_prefix} Error - #{data[:summary]}"

      recipients exception_recipients
      from       sender_address

      body       data
    end

    private

      def sanitize_backtrace(trace)
        re = Regexp.new(/^#{Regexp.escape(rails_root)}/)
        trace.map { |line| Pathname.new(line.gsub(re, "[RAILS_ROOT]")).cleanpath.to_s }
      end

      def rails_root
        @rails_root ||= Pathname.new(RAILS_ROOT).cleanpath.to_s
      end

  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
relevance-chatterbox-0.2.1 lib/consumers/email_consumer.rb
relevance-chatterbox-0.2.2 lib/consumers/email_consumer.rb
relevance-chatterbox-0.3.0 lib/consumers/email_consumer.rb