Created
February 27, 2013 00:13
-
-
Save johnskopis/5043622 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProxyMail | |
def initialize(contents) | |
# The mail gem is implemented using STDERR.puts for all warnings | |
# We want to suppress warnings of the format: | |
# WARNING: Could not parse (and so ignorning) 'Your message:' | |
@stderr = $stderr.clone | |
silence_warnings do | |
@mail = Mail.new(contents) | |
end | |
end | |
def silence_warnings | |
$stderr.reopen File.new('/dev/null', 'w+') | |
yield | |
$stderr.reopen @stderr | |
end | |
def method_missing(meth, *args, &block) | |
rval = nil | |
if @mail.respond_to?(meth) | |
silence_warnings do | |
rval = @mail.send(meth, *args, &block) | |
end | |
else | |
raise NameError, "Mail does not respond to #{meth}" | |
end | |
rval | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment