Add methods to manipulate Repl context
This commit is contained in:
parent
2ff7dc0866
commit
9d6a19507b
|
@ -150,13 +150,13 @@ Cylon.config = function(opts) {
|
|||
* @return {void}
|
||||
*/
|
||||
Cylon.repl = function repl() {
|
||||
var repl = new Repl(
|
||||
var instance = new Repl(
|
||||
{ prompt: "mcp > " },
|
||||
{ robots: this.robots }
|
||||
);
|
||||
|
||||
repl.start();
|
||||
}
|
||||
instance.start();
|
||||
};
|
||||
|
||||
// Public: Halts the API and the robots
|
||||
//
|
||||
|
|
27
lib/repl.js
27
lib/repl.js
|
@ -53,3 +53,30 @@ Repl.prototype.start = function() {
|
|||
this.emit("reset");
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
// add a value to the context
|
||||
Repl.prototype.addContext = function(key, value) {
|
||||
this.context[key] = value;
|
||||
this.repl.context[key] = value;
|
||||
};
|
||||
|
||||
// remove a value from the context
|
||||
Repl.prototype.removeContext = function(key) {
|
||||
delete this.context[key];
|
||||
delete this.repl.context[key];
|
||||
};
|
||||
|
||||
// set the context to the provided object
|
||||
Repl.prototype.setContext = function(object) {
|
||||
_.each(this.context, function(value, key) {
|
||||
if (this.context.hasOwnProperty(key)) {
|
||||
this.removeContext(key);
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
_.each(object, function(value, key) {
|
||||
if (object.hasOwnProperty(key)) {
|
||||
this.addContext(key, value);
|
||||
}
|
||||
}.bind(this));
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue