- fix failing tests caused by scoping problems and instance_eval

This commit is contained in:
Jordan Sissel 2013-05-07 11:14:50 -07:00
parent 6994d1dccf
commit 3b11b904a1

View file

@ -93,17 +93,22 @@ class LogStash::Outputs::Email < LogStash::Outputs::Base
public public
def register def register
require "mail" require "mail"
# Mail uses instance_eval which changes the scope of self so @options is
# inaccessible from inside 'Mail.defaults'. So set a local variable instead.
options = @options
if @via == "smtp" if @via == "smtp"
Mail.defaults do Mail.defaults do
delivery_method :smtp, { delivery_method :smtp, {
:address => @options.fetch("smtpIporHost", "localhost"), :address => options.fetch("smtpIporHost", "localhost"),
:port => @options.fetch("port", 25), :port => options.fetch("port", 25),
:domain => @options.fetch("domain", "localhost"), :domain => options.fetch("domain", "localhost"),
:user_name => @options.fetch("userName", nil), :user_name => options.fetch("userName", nil),
:password => @options.fetch("password", nil), :password => options.fetch("password", nil),
:authentication => @options.fetch("authenticationType", nil), :authentication => options.fetch("authenticationType", nil),
:enable_starttls_auto => @options.fetch("starttls", false), :enable_starttls_auto => options.fetch("starttls", false),
:debug => @options.fetch("debug", false) :debug => options.fetch("debug", false)
} }
end end
elsif @via == 'sendmail' elsif @via == 'sendmail'
@ -112,7 +117,7 @@ class LogStash::Outputs::Email < LogStash::Outputs::Base
end end
else else
Mail.defaults do Mail.defaults do
delivery_method :@via, @options delivery_method :@via, options
end end
end # @via tests end # @via tests
@logger.debug("Email Output Registered!", :config => @config) @logger.debug("Email Output Registered!", :config => @config)