Permalink
Browse files

Merge pull request #97 from langpavel/switch-refactoring

Remove unnecessary switch, expose available transports via hash on Transport constructor
  • Loading branch information...
2 parents bdda98b + be98e8d commit 1cdf3f63fb9a0304fee997048dfb229a4dc2f84d @andris9 andris9 committed Aug 14, 2012
Showing with 16 additions and 16 deletions.
  1. +16 −16 lib/transport.js
View
@@ -8,6 +8,16 @@ var SendmailTransport = require("./engines/sendmail"),
module.exports.Transport = Transport;
/**
+ * Hash of available transports (uppercase) and their constructor methods
+ */
+Transport.transports = {
+ "SMTP": SMTPTransport,
+ "SES": SESTransport,
+ "SENDMAIL": SendmailTransport,
+ "STUB": StubTransport
+}
+
+/**
* <p>Generates a Transport object that can be used to deliver e-mail.</p>
*
* <p>All transport objects need to have <code>sendMail</code> property defined
@@ -23,21 +33,11 @@ function Transport(type, options){
this.transportType = (type || "").toString().trim().toUpperCase();
this.dkimOptions = false;
- switch(this.transportType){
- case "SMTP":
- this.transport = new SMTPTransport(this.options);
- break;
- case "SES":
- this.transport = new SESTransport(this.options);
- break;
- case "SENDMAIL":
- this.transport = new SendmailTransport(this.options);
- break;
- case "STUB":
- this.transport = new StubTransport(this.options);
- break;
- default:
- this.transport = false;
+ var constructor = Transport.transports[this.transportType];
+ if(constructor){
+ this.transport = new constructor(this.options);
+ }else{
+ this.transport = false;
}
}
@@ -107,4 +107,4 @@ Transport.prototype.close = function(callback){
callback(null);
}
}
-};
+};

0 comments on commit 1cdf3f6

Please sign in to comment.