Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Remove unnecessary switch, expose available transports via hash on Transport constructor #97

Merged
merged 1 commit into from

3 participants

@langpavel

No description provided.

@travisbot

This pull request passes (merged be98e8d into bdda98b).

@andris9 andris9 merged commit 1cdf3f6 into andris9:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 14, 2012
  1. @langpavel
This page is out of date. Refresh to see the latest.
Showing with 16 additions and 16 deletions.
  1. +16 −16 lib/transport.js
View
32 lib/transport.js
@@ -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);
}
}
-};
+};
Something went wrong with that request. Please try again.