Skip to content

Commit

Permalink
Convert HubConfig into Petal.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsamarin committed Mar 30, 2012
1 parent d43b666 commit 61f225c
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion hub/HubConfig.js
Expand Up @@ -2,6 +2,9 @@

var fs = require ("fs");
var path = require ("path");
var util = require ("util");

var Petal = require ("./Petal.js");
var FileUtils = require ("./FileUtils.js");

/**
Expand All @@ -11,7 +14,8 @@ var FileUtils = require ("./FileUtils.js");
* petals to access, update, and modify global configuration.
**/

var HubConfig = function (locations) {
var HubConfig = function () {
Petal.call (this);

this.path = null;

Expand All @@ -27,6 +31,8 @@ var HubConfig = function (locations) {
this.data.IRC.servers = [];
};

util.inherits (HubConfig, Petal);

HubConfig.prototype.location = path.join (FileUtils.home (), ".lic", "config.json");


Expand Down Expand Up @@ -135,6 +141,8 @@ HubConfig.prototype.write_file = function(file, callback) {

data = JSON.stringify (this.data, null, 4);

console.log ("Saving configuration: %s", file);

fs.writeFile (file, data, 'utf8', function(error) {
callback.call (self, error);
});
Expand All @@ -161,4 +169,17 @@ HubConfig.prototype.load_config_data = function (data) {

};

/**
* HubConfig#shutdown:
* This command is called when the hub begins to shutdown.
* It writes changes in the configuration to disk and calls the callback.
**/
HubConfig.prototype.shutdown = function(callback) {
this.write_file (this.location, function(error) {
if (callback) {
callback.call (this, error);
}
});
};

module.exports = HubConfig;

0 comments on commit 61f225c

Please sign in to comment.