Skip to content

Commit 62bfd5a

Browse files
committed
Use object function syntax
1 parent 5942721 commit 62bfd5a

File tree

3 files changed

+49
-49
lines changed

3 files changed

+49
-49
lines changed

index.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ let DeployPluginBase = require('ember-cli-deploy-plugin');
99
module.exports = {
1010
name: 'ember-cli-deploy-redis',
1111

12-
createDeployPlugin: function(options) {
12+
createDeployPlugin(options) {
1313
var Redis = require('./lib/redis');
1414

1515
var DeployPlugin = DeployPluginBase.extend({
1616
name: options.name,
1717
defaultConfig: {
1818
host: 'localhost',
19-
port: function(context) {
19+
port(context) {
2020
if (context.tunnel && context.tunnel.srcPort) {
2121
return context.tunnel.srcPort;
2222
} else {
@@ -25,15 +25,15 @@ module.exports = {
2525
},
2626
filePattern: 'index.html',
2727
maxRecentUploads: 10,
28-
distDir: function(context) {
28+
distDir(context) {
2929
return context.distDir;
3030
},
31-
keyPrefix: function(context){
31+
keyPrefix(context){
3232
return context.project.name() + ':index';
3333
},
3434
activationSuffix: 'current',
3535
activeContentSuffix: 'current-content',
36-
didDeployMessage: function(context){
36+
didDeployMessage(context){
3737
var revisionKey = context.revisionData && context.revisionData.revisionKey;
3838
var activatedRevisionKey = context.revisionData && context.revisionData.activatedRevisionKey;
3939
if (revisionKey && !activatedRevisionKey) {
@@ -42,10 +42,10 @@ module.exports = {
4242
+ "ember deploy:activate " + context.deployTarget + " --revision=" + revisionKey + "\n";
4343
}
4444
},
45-
revisionKey: function(context) {
45+
revisionKey(context) {
4646
return context.commandOptions.revision || (context.revisionData && context.revisionData.revisionKey);
4747
},
48-
redisDeployClient: function(context, pluginHelper) {
48+
redisDeployClient(context, pluginHelper) {
4949
var redisLib = context._redisLib;
5050
var options = {
5151
url: pluginHelper.readConfig('url'),
@@ -61,11 +61,11 @@ module.exports = {
6161
return new Redis(options, redisLib);
6262
},
6363

64-
revisionData: function(context) {
64+
revisionData(context) {
6565
return context.revisionData;
6666
}
6767
},
68-
configure: function(/* context */) {
68+
configure(/* context */) {
6969
this.log('validating config', { verbose: true });
7070

7171
if (!this.pluginConfig.url) {
@@ -83,7 +83,7 @@ module.exports = {
8383
this.log('config ok', { verbose: true });
8484
},
8585

86-
upload: async function(/* context */) {
86+
async upload(/* context */) {
8787
let redisDeployClient = this.readConfig('redisDeployClient');
8888
let revisionKey = this.readConfig('revisionKey');
8989
let distDir = this.readConfig('distDir');
@@ -103,7 +103,7 @@ module.exports = {
103103
}
104104
},
105105

106-
willActivate: async function(/* context */) {
106+
async willActivate(/* context */) {
107107
let redisDeployClient = this.readConfig('redisDeployClient');
108108
let keyPrefix = this.readConfig('keyPrefix');
109109

@@ -115,7 +115,7 @@ module.exports = {
115115
};
116116
},
117117

118-
activate: async function(/* context */) {
118+
async activate(/* context */) {
119119
let redisDeployClient = this.readConfig('redisDeployClient');
120120
let revisionKey = this.readConfig('revisionKey');
121121
let keyPrefix = this.readConfig('keyPrefix');
@@ -137,14 +137,14 @@ module.exports = {
137137
}
138138
},
139139

140-
didDeploy: function(/* context */){
140+
didDeploy(/* context */){
141141
var didDeployMessage = this.readConfig('didDeployMessage');
142142
if (didDeployMessage) {
143143
this.log(didDeployMessage);
144144
}
145145
},
146146

147-
fetchInitialRevisions: async function(/* context */) {
147+
async fetchInitialRevisions(/* context */) {
148148
let redisDeployClient = this.readConfig('redisDeployClient');
149149
let keyPrefix = this.readConfig('keyPrefix');
150150

@@ -160,7 +160,7 @@ module.exports = {
160160
}
161161
},
162162

163-
fetchRevisions: async function(/* context */) {
163+
async fetchRevisions(/* context */) {
164164
let redisDeployClient = this.readConfig('redisDeployClient');
165165
let keyPrefix = this.readConfig('keyPrefix');
166166

@@ -176,16 +176,16 @@ module.exports = {
176176
}
177177
},
178178

179-
_readFileContents: async function(path) {
179+
async _readFileContents(path) {
180180
let buffer = await fs.promises.readFile(path);
181181
return buffer.toString();
182182
},
183183

184-
_logUploadSuccessMessage: function(key) {
184+
_logUploadSuccessMessage(key) {
185185
this.log('Uploaded with key `' + key + '`', { verbose: true });
186186
},
187187

188-
_logErrorMessage: function(error) {
188+
_logErrorMessage(error) {
189189
this.log(error, { color: 'red' });
190190
}
191191
});

lib/redis.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var RSVP = require('rsvp');
33

44
module.exports = CoreObject.extend({
55

6-
init: function(options, lib) {
6+
init(options, lib) {
77
this._super();
88
var redisOptions = {};
99
var RedisLib = lib;
@@ -36,7 +36,7 @@ module.exports = CoreObject.extend({
3636
this._activationSuffix = options.activationSuffix || 'current';
3737
},
3838

39-
upload: async function(/*keyPrefix, revisionKey, value*/) {
39+
async upload(/*keyPrefix, revisionKey, value*/) {
4040
let args = Array.prototype.slice.call(arguments);
4141

4242
let keyPrefix = args.shift();
@@ -55,13 +55,13 @@ module.exports = CoreObject.extend({
5555
return redisKey;
5656
},
5757

58-
activate: async function(keyPrefix, revisionKey, activationSuffix, activeContentSuffix) {
58+
async activate(keyPrefix, revisionKey, activationSuffix, activeContentSuffix) {
5959
let revisions = await this._listRevisions(keyPrefix);
6060
this._validateRevisionKey(revisionKey, revisions);
6161
await this._activateRevision(keyPrefix, revisionKey, activationSuffix, activeContentSuffix);
6262
},
6363

64-
fetchRevisions: async function(keyPrefix) {
64+
async fetchRevisions(keyPrefix) {
6565
let revisions = await this._listRevisions(keyPrefix);
6666
let results = await RSVP.hash({
6767
current: this.activeRevision(keyPrefix),
@@ -79,12 +79,12 @@ module.exports = CoreObject.extend({
7979
});
8080
},
8181

82-
activeRevision: function(keyPrefix) {
82+
activeRevision(keyPrefix) {
8383
var currentKey = keyPrefix + ':' + this._activationSuffix;
8484
return this._client.get(currentKey);
8585
},
8686

87-
_revisionData: async function(keyPrefix, revisions) {
87+
async _revisionData(keyPrefix, revisions) {
8888
if (revisions.length === 0) {
8989
return;
9090
}
@@ -101,34 +101,34 @@ module.exports = CoreObject.extend({
101101
});
102102
},
103103

104-
_listRevisions: function(keyPrefix) {
104+
_listRevisions(keyPrefix) {
105105
var client = this._client;
106106
var listKey = keyPrefix + ':revisions';
107107
return client.zrevrange(listKey, 0, -1);
108108
},
109109

110-
_validateRevisionKey: function(revisionKey, revisions) {
110+
_validateRevisionKey(revisionKey, revisions) {
111111
if (revisions.indexOf(revisionKey) === -1) {
112112
throw new Error('`' + revisionKey + '` is not a valid revision key');
113113
}
114114
return;
115115
},
116116

117-
_activateRevisionKey: function(keyPrefix, revisionKey, activationSuffix) {
117+
_activateRevisionKey(keyPrefix, revisionKey, activationSuffix) {
118118
var currentKey = keyPrefix + ':' + activationSuffix;
119119

120120
return this._client.set(currentKey, revisionKey);
121121
},
122122

123-
_activateRevision: function(keyPrefix, revisionKey, activationSuffix, activeContentSuffix) {
123+
_activateRevision(keyPrefix, revisionKey, activationSuffix, activeContentSuffix) {
124124
if (activeContentSuffix) {
125125
return this._copyRevisionAndActivateRevisionKey(keyPrefix, revisionKey, activationSuffix, activeContentSuffix);
126126
}
127127

128128
return this._activateRevisionKey(keyPrefix, revisionKey, activationSuffix);
129129
},
130130

131-
_copyRevisionAndActivateRevisionKey: async function(
131+
async _copyRevisionAndActivateRevisionKey(
132132
keyPrefix, revisionKey, activationSuffix, activeContentSuffix) {
133133
let client = this._client;
134134
let activeContentKey = keyPrefix + ':' + activeContentSuffix;
@@ -139,7 +139,7 @@ module.exports = CoreObject.extend({
139139
await this._activateRevisionKey(keyPrefix, revisionKey, activationSuffix);
140140
},
141141

142-
_uploadIfKeyDoesNotExist: async function(redisKey, value) {
142+
async _uploadIfKeyDoesNotExist(redisKey, value) {
143143
var client = this._client;
144144
var allowOverwrite = !!this._allowOverwrite;
145145

@@ -150,20 +150,20 @@ module.exports = CoreObject.extend({
150150
return client.set(redisKey, value);
151151
},
152152

153-
_uploadRevisionData: async function(keyPrefix, revisionKey, revisionData) {
153+
async _uploadRevisionData(keyPrefix, revisionKey, revisionData) {
154154
let client = this._client;
155155
let redisKey = keyPrefix + ':revision-data:' + revisionKey;
156156
await client.set(redisKey, JSON.stringify(revisionData));
157157
},
158158

159-
_updateRecentUploadsList: async function(keyPrefix, revisionKey) {
159+
async _updateRecentUploadsList(keyPrefix, revisionKey) {
160160
let client = this._client;
161161
let score = new Date().getTime();
162162
let listKey = keyPrefix + ':revisions';
163163
await client.zadd(listKey, score, revisionKey);
164164
},
165165

166-
_trimRecentUploadsList: async function(keyPrefix, maxEntries) {
166+
async _trimRecentUploadsList(keyPrefix, maxEntries) {
167167
let client = this._client;
168168
let listKey = keyPrefix + ':revisions';
169169

@@ -187,7 +187,7 @@ module.exports = CoreObject.extend({
187187
await RSVP.all(promises);
188188
},
189189

190-
_stripUsernameFromConfigUrl: function(configUrl) {
190+
_stripUsernameFromConfigUrl(configUrl) {
191191
var regex = /redis:\/\/(\w+):(\w+)(.*)/;
192192
var matches = configUrl.match(regex);
193193

tests/unit/index-test.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var IoRedis = require("ioredis");
66
var sandbox = require("sinon").createSandbox();
77

88
var stubProject = {
9-
name: function() {
9+
name() {
1010
return "my-project";
1111
}
1212
};
@@ -19,8 +19,8 @@ describe("redis plugin", function() {
1919
mockUi = {
2020
verbose: true,
2121
messages: [],
22-
write: function() {},
23-
writeLine: function(message) {
22+
write() {},
23+
writeLine(message) {
2424
this.messages.push(message);
2525
}
2626
};
@@ -537,9 +537,9 @@ describe("redis plugin", function() {
537537
filePattern: "index.html",
538538
distDir: "tests",
539539
revisionKey: "123abc",
540-
redisDeployClient: function(/* context */) {
540+
redisDeployClient(/* context */) {
541541
return {
542-
upload: function(keyPrefix, revisionKey) {
542+
upload(keyPrefix, revisionKey) {
543543
return RSVP.resolve(keyPrefix + ":" + revisionKey);
544544
}
545545
};
@@ -572,9 +572,9 @@ describe("redis plugin", function() {
572572
filePattern: "index.html",
573573
distDir: "tests",
574574
revisionKey: "123abc",
575-
redisDeployClient: function(/* context */) {
575+
redisDeployClient(/* context */) {
576576
return {
577-
activate: function() {
577+
activate() {
578578
activateCalled = true;
579579
}
580580
};
@@ -603,9 +603,9 @@ describe("redis plugin", function() {
603603
filePattern: "index.html",
604604
distDir: "tests",
605605
revisionKey: "123abc",
606-
redisDeployClient: function(/* context */) {
606+
redisDeployClient(/* context */) {
607607
return {
608-
activate: function() {
608+
activate() {
609609
return RSVP.reject("some-error");
610610
}
611611
};
@@ -632,10 +632,10 @@ describe("redis plugin", function() {
632632
var context = {
633633
deployTarget: "qa",
634634
ui: {
635-
write: function(message) {
635+
write(message) {
636636
messageOutput = messageOutput + message;
637637
},
638-
writeLine: function(message) {
638+
writeLine(message) {
639639
messageOutput = messageOutput + message + "\n";
640640
}
641641
},
@@ -678,9 +678,9 @@ describe("redis plugin", function() {
678678
filePattern: "index.html",
679679
distDir: "tests",
680680
revisionKey: "123abc",
681-
redisDeployClient: function(/* context */) {
681+
redisDeployClient(/* context */) {
682682
return {
683-
fetchRevisions: function(/* keyPrefix, revisionKey */) {
683+
fetchRevisions(/* keyPrefix, revisionKey */) {
684684
return RSVP.resolve([
685685
{
686686
revision: "a",
@@ -726,9 +726,9 @@ describe("redis plugin", function() {
726726
filePattern: "index.html",
727727
distDir: "tests",
728728
revisionKey: "123abc",
729-
redisDeployClient: function(/* context */) {
729+
redisDeployClient(/* context */) {
730730
return {
731-
fetchRevisions: function(/* keyPrefix, revisionKey */) {
731+
fetchRevisions(/* keyPrefix, revisionKey */) {
732732
return RSVP.resolve([
733733
{
734734
revision: "a",

0 commit comments

Comments
 (0)