Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

logging and configuration

  • Loading branch information...
commit 734f1308e338a8b95e992ec3f1dab070a47818a3 1 parent ca19d96
Dan Pickett authored
Showing with 38 additions and 1 deletion.
  1. +3 −1 Gemfile
  2. +35 −0 lib/postmaster_general.rb
View
4 Gemfile
@@ -1,7 +1,9 @@
source "http://rubygems.org"
# Add dependencies required to use your gem here.
# Example:
-# gem "activesupport", ">= 2.3.5"
+
+gem "actionmailer", "~> 3.0"
+gem "configatron"
# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
View
35 lib/postmaster_general.rb
@@ -0,0 +1,35 @@
+require "actionmailer"
+
+require 'fileutils'
+
+module PostmasterGeneral do
+ def self.log_directory=(path)
+ configatron.postmaster_general.log_directory = path
+ end
+
+ def self.log_directory
+ configatron.postmaster_general.log_directory
+ end
+
+ def self.log_deliveries(path, &block)
+ before_index = ActionMailer::Base.deliveries.size - 1
+ before_index = 0 if before_index < 0
+
+ yield
+
+ log_path = log_directory.join(path)
+
+ FileUtils.mkdir_p(File.dirname(log_path))
+ FileUtils.rm_f(log_path)
+
+ ActionMailer::Base.deliveries[before_index..-1].each do |mail|
+ File.open(log_path, "w+") do |f|
+ f << "=================="
+ f << mail.encoded
+ f << "=================="
+ end
+ end
+ end
+end
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.