Skip to content

Commit a1c3289

Browse files
committed
Allow configuration of redis using a url property instead of host/port/etc
1 parent b8e77c1 commit a1c3289

File tree

3 files changed

+90
-40
lines changed

3 files changed

+90
-40
lines changed

lib/redis.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@ var Promise = require('ember-cli/lib/ext/promise');
33

44
module.exports = CoreObject.extend({
55
init: function(options) {
6-
var redisOptions = {
7-
host: options.host,
8-
port: options.port
9-
};
6+
if (options.redisClient) {
7+
this._client = options.redisClient;
8+
} else if (options.url) {
9+
this._client = require('then-redis').createClient(options.url);
10+
} else {
11+
var redisOptions = {
12+
host: options.host,
13+
port: options.port
14+
};
1015

11-
if (options.password) {
12-
redisOptions.password = options.password;
13-
}
14-
15-
this._client = options.redisClient || require('then-redis').createClient(redisOptions);
16+
if (options.password) {
17+
redisOptions.password = options.password;
18+
}
1619

20+
this._client = require('then-redis').createClient(redisOptions);
21+
}
1722
this._maxNumberOfRecentUploads = 10;
1823
},
1924

lib/utilities/validate-config.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ var chalk = require('chalk');
44
var yellow = chalk.yellow;
55
var blue = chalk.blue;
66

7+
function applyDefaultConfigIfNecessary(config, prop, defaultConfig, ui){
8+
if (!config[prop]) {
9+
var value = defaultConfig[prop];
10+
config[prop] = value;
11+
ui.write(blue('| '));
12+
ui.writeLine(yellow('- Missing config: `' + prop + '`, using default: `' + value + '`'));
13+
}
14+
}
15+
716
module.exports = function(ui, config) {
817
ui.write(blue('| '));
918
ui.writeLine(blue('- validating config'));
@@ -14,14 +23,12 @@ module.exports = function(ui, config) {
1423
filePattern: 'dist/index.html'
1524
};
1625

17-
['host', 'port', 'filePattern'].forEach(function(prop) {
18-
if (!config[prop]) {
19-
var value = defaultConfig[prop];
20-
config[prop] = value;
21-
ui.write(blue('| '));
22-
ui.writeLine(yellow('- Missing config: `' + prop + '`, using default: `' + value + '`'));
23-
}
24-
});
26+
if (!config.url) {
27+
['host', 'port'].forEach(function(prop) {
28+
applyDefaultConfigIfNecessary(config, prop, defaultConfig, ui);
29+
});
30+
}
31+
applyDefaultConfigIfNecessary(config, 'filePattern', defaultConfig, ui);
2532

2633
return Promise.resolve();
2734
}

tests/unit/lib/utilities/validate-config-nodetest.js

Lines changed: 61 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ describe('validate-config', function() {
1010
});
1111

1212
beforeEach(function() {
13-
config = { };
14-
1513
mockUi = {
1614
messages: [],
1715
write: function() { },
@@ -21,30 +19,70 @@ describe('validate-config', function() {
2119
};
2220
});
2321

24-
it('warns about missing optional config', function() {
25-
return assert.isFulfilled(subject(mockUi, config))
26-
.then(function() {
27-
var messages = mockUi.messages.reduce(function(previous, current) {
28-
if (/- Missing config:\s.*, using default:\s/.test(current)) {
29-
previous.push(current);
30-
}
22+
describe('without providing config', function () {
23+
beforeEach(function() {
24+
config = { };
25+
});
26+
it('warns about missing optional config', function() {
27+
return assert.isFulfilled(subject(mockUi, config))
28+
.then(function() {
29+
var messages = mockUi.messages.reduce(function(previous, current) {
30+
if (/- Missing config:\s.*, using default:\s/.test(current)) {
31+
previous.push(current);
32+
}
3133

32-
return previous;
33-
}, []);
34+
return previous;
35+
}, []);
3436

35-
assert.equal(messages.length, 3);
36-
});
37-
});
37+
assert.equal(messages.length, 3);
38+
});
39+
});
3840

39-
it('adds default config to the config object', function() {
40-
return assert.isFulfilled(subject(mockUi, config))
41-
.then(function() {
42-
assert.isDefined(config.host);
43-
assert.isDefined(config.port);
44-
});
41+
it('adds default config to the config object', function() {
42+
return assert.isFulfilled(subject(mockUi, config))
43+
.then(function() {
44+
assert.isDefined(config.host);
45+
assert.isDefined(config.port);
46+
});
47+
});
48+
49+
it('resolves', function() {
50+
return assert.isFulfilled(subject(mockUi, config));
51+
})
4552
});
4653

47-
it('resolves if config is ok', function() {
48-
return assert.isFulfilled(subject(mockUi, config));
49-
})
54+
describe('with a url provided', function () {
55+
beforeEach(function() {
56+
config = {
57+
url: 'redis://localhost:6379'
58+
};
59+
});
60+
it('only warns about missing optional filePattern', function() {
61+
return assert.isFulfilled(subject(mockUi, config))
62+
.then(function() {
63+
var messages = mockUi.messages.reduce(function(previous, current) {
64+
if (/- Missing config:\s.*, using default:\s/.test(current)) {
65+
previous.push(current);
66+
}
67+
68+
return previous;
69+
}, []);
70+
71+
assert.equal(messages.length, 1);
72+
});
73+
});
74+
75+
it('does not add default config to the config object', function() {
76+
return assert.isFulfilled(subject(mockUi, config))
77+
.then(function() {
78+
assert.isUndefined(config.host);
79+
assert.isUndefined(config.port);
80+
assert.isDefined(config.filePattern);
81+
});
82+
});
83+
84+
it('resolves', function() {
85+
return assert.isFulfilled(subject(mockUi, config));
86+
})
87+
});
5088
});

0 commit comments

Comments
 (0)