Refactor Hash.fetch usage to provide default values

Rather than explicitly running through if/else blocks, it's easier to
read if the default value is provided against the Hash method calls directly.
This commit is contained in:
Kushal Pisavadia 2013-04-16 22:36:05 +01:00
parent c83c1444a3
commit 5d70c6026e

View file

@ -94,54 +94,15 @@ class LogStash::Outputs::Email < LogStash::Outputs::Base
def register
require "mail"
if @via == "smtp"
debug = @options.include?("debug")
if !debug
debug = false
else
debug = @options.fetch("debug")
end
smtpIporHost = @options.include?("smtpIporHost")
if !smtpIporHost
smtpIporHost = "localhost"
else
smtpIporHost = @options.fetch("smtpIporHost")
end
domain = @options.include?("domain")
if !domain
domain = "localhost"
else
domain = @options.fetch("domain")
end
port = @options.include?("port")
if !port
port = 25
else
port = @options.fetch("port")
end
tls = @options.include?("starttls")
if !tls
tls = false
else
tls = @options.fetch("starttls")
end
pass = @options.include?("password")
if !pass
pass = nil
else
pass = @options.fetch("password")
end
userName = @options.include?("userName")
if !userName
userName = nil
else
userName = @options.fetch("userName")
end
authenticationType = @options.include?("authenticationType")
if !authenticationType
authenticationType = nil
else
authenticationType = @options.fetch("authenticationType")
end
debug = @options.fetch("debug", false)
smtpIporHost = @options.fetch("smtpIporHost", "localhost")
domain = @options.fetch("domain", "localhost")
port = @options.fetch("port", 25)
tls = @options.fetch("starttls", false)
pass = @options.fetch("password", nil)
userName = @options.fetch("userName", nil)
authenticationType = @options.fetch("authenticationType", nil)
Mail.defaults do
delivery_method :smtp , { :address => smtpIporHost,
:port => port,