Switch to single Cylon#config function

This commit is contained in:
Andrew Stewart 2014-09-15 14:46:24 -07:00
parent c443b486cc
commit 7560507f11
2 changed files with 17 additions and 25 deletions

View File

@ -88,24 +88,17 @@ Cylon.start = function start() {
// //
// opts - object containing configuration key/value pairs // opts - object containing configuration key/value pairs
// //
// Returns the updated config // Returns the current config
Cylon.setConfig = function(opts) { Cylon.config = function(opts) {
for (var o in opts) { if (opts && typeof(opts) === 'object' && !Array.isArray(opts)) {
Config[o] = opts[o]; for (var o in opts) {
Config[o] = opts[o];
}
} }
return Config; return Config;
}; };
// Public: Fetches a value from the internal configuration
//
// key - string key to be fetched from config
//
// Returns the config value
Cylon.config = function(key) {
return Config[key];
};
// Public: Halts the API and the robots // Public: Halts the API and the robots
// //
// callback - callback to be triggered when Cylon is ready to shutdown // callback - callback to be triggered when Cylon is ready to shutdown

View File

@ -95,7 +95,7 @@ describe("Cylon", function() {
}); });
}); });
describe("#setConfig", function() { describe("#config", function() {
beforeEach(function() { beforeEach(function() {
for (var c in Config) { for (var c in Config) {
delete Config[c]; delete Config[c];
@ -103,30 +103,29 @@ describe("Cylon", function() {
}); });
it("sets config variables", function() { it("sets config variables", function() {
Cylon.setConfig({ a: 1, b: 2 }); Cylon.config({ a: 1, b: 2 });
expect(Config.a).to.be.eql(1); expect(Config.a).to.be.eql(1);
expect(Config.b).to.be.eql(2); expect(Config.b).to.be.eql(2);
}); });
it("updates existing config", function() { it("updates existing config", function() {
Cylon.setConfig({ a: 1, b: 2 }); Cylon.config({ a: 1, b: 2 });
Cylon.setConfig({ a: 3 }); Cylon.config({ a: 3 });
expect(Config.a).to.be.eql(3); expect(Config.a).to.be.eql(3);
expect(Config.b).to.be.eql(2); expect(Config.b).to.be.eql(2);
}); });
it("returns updated config", function() { it("returns updated config", function() {
var config = Cylon.setConfig({ a: 1, b: 2 }); var config = Cylon.config({ a: 1, b: 2 });
expect(Config).to.be.eql(config); expect(Config).to.be.eql(config);
}); });
});
describe("#config", function() { it("doesn't ignores non-object arguments", function() {
it("returns a value from the Config object", function() { var config = Cylon.config({ a: 1, b: 2 });
Config.a = "hello world"; Cylon.config(["a", 1, "b", 2]);
expect(Cylon.config("a")).to.be.eql("hello world"); Cylon.config("hello world");
delete Config.a; expect(Config).to.be.eql(config);
}) });
}); });
describe("#halt", function() { describe("#halt", function() {