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
//
// Returns the updated config
Cylon.setConfig = function(opts) {
for (var o in opts) {
Config[o] = opts[o];
// Returns the current config
Cylon.config = function(opts) {
if (opts && typeof(opts) === 'object' && !Array.isArray(opts)) {
for (var o in opts) {
Config[o] = opts[o];
}
}
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
//
// 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() {
for (var c in Config) {
delete Config[c];
@ -103,30 +103,29 @@ describe("Cylon", 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.b).to.be.eql(2);
});
it("updates existing config", function() {
Cylon.setConfig({ a: 1, b: 2 });
Cylon.setConfig({ a: 3 });
Cylon.config({ a: 1, b: 2 });
Cylon.config({ a: 3 });
expect(Config.a).to.be.eql(3);
expect(Config.b).to.be.eql(2);
});
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);
});
});
describe("#config", function() {
it("returns a value from the Config object", function() {
Config.a = "hello world";
expect(Cylon.config("a")).to.be.eql("hello world");
delete Config.a;
})
it("doesn't ignores non-object arguments", function() {
var config = Cylon.config({ a: 1, b: 2 });
Cylon.config(["a", 1, "b", 2]);
Cylon.config("hello world");
expect(Config).to.be.eql(config);
});
});
describe("#halt", function() {