Return the GitStats object.

This commit is contained in:
Ionică Bizău 2015-02-09 15:11:47 +02:00
parent 802bfecb37
commit 29608f50c4

View file

@ -42,7 +42,7 @@ var GitStats = module.exports = {};
* - `hash` (String): The commit hash. * - `hash` (String): The commit hash.
* *
* @param {Function} callback The callback function. * @param {Function} callback The callback function.
* @return {undefined} * @return {GitStats} The `GitStats` object.
*/ */
GitStats.record = function (data, callback) { GitStats.record = function (data, callback) {
@ -54,15 +54,18 @@ GitStats.record = function (data, callback) {
} }
if (!data.date || !/^Moment|Date$/.test(data.date.constructor.name)) { if (!data.date || !/^Moment|Date$/.test(data.date.constructor.name)) {
return callback(new Error("The date field should be a string or a date object.")); callback(new Error("The date field should be a string or a date object."));
return GitStats;
} }
if (typeof data.hash !== "string" || !data.hash) { if (typeof data.hash !== "string" || !data.hash) {
return callback(new Error("Invalid hash.")); callback(new Error("Invalid hash."));
return GitStats;
} }
if (typeof data.url !== "string" || !data.url) { if (typeof data.url !== "string" || !data.url) {
return callback(new Error("Invalid url field. This commit is not recorded into the git-stats history since you didn't added the remote url. You can import the previous commits using the git-stats-importer tool.")); callback(new Error("Invalid url field. This commit is not recorded into the git-stats history since you didn't added the remote url. You can import the previous commits using the git-stats-importer tool."));
return GitStats;
} }
// Get stats // Get stats
@ -77,6 +80,8 @@ GitStats.record = function (data, callback) {
GitStats.save(stats, callback); GitStats.save(stats, callback);
}); });
return GitStats;
}; };
/** /**
@ -86,7 +91,7 @@ GitStats.record = function (data, callback) {
* @name get * @name get
* @function * @function
* @param {Function} callback The callback function. * @param {Function} callback The callback function.
* @return {undefined} * @return {GitStats} The `GitStats` object.
*/ */
GitStats.get = function (callback) { GitStats.get = function (callback) {
Fs.readFile(STORE_PATH, "utf-8", function (err, data) { Fs.readFile(STORE_PATH, "utf-8", function (err, data) {
@ -98,6 +103,7 @@ GitStats.get = function (callback) {
} }
callback(null, data); callback(null, data);
}); });
return GitStats;
}; };
/** /**
@ -108,10 +114,11 @@ GitStats.get = function (callback) {
* @function * @function
* @param {Object} stats The stats to be saved. * @param {Object} stats The stats to be saved.
* @param {Function} callback The callback function. * @param {Function} callback The callback function.
* @return {undefined} * @return {GitStats} The `GitStats` object.
*/ */
GitStats.save = function (stats, callback) { GitStats.save = function (stats, callback) {
Fs.writeFile(STORE_PATH, JSON.stringify(stats, null, 1), callback); Fs.writeFile(STORE_PATH, JSON.stringify(stats, null, 1), callback);
return GitStats;
}; };
/** /**
@ -127,7 +134,7 @@ GitStats.save = function (stats, callback) {
* - `format` (String): The format of the date (default: `"MMM D, YYYY"`). * - `format` (String): The format of the date (default: `"MMM D, YYYY"`).
* *
* @param {Function} callback The callback function called with the current day formatted (type: string) and the `Moment` date object. * @param {Function} callback The callback function called with the current day formatted (type: string) and the `Moment` date object.
* @return {undefined} * @return {GitStats} The `GitStats` object.
*/ */
GitStats.iterateDays = function (data, callback) { GitStats.iterateDays = function (data, callback) {
@ -155,6 +162,8 @@ GitStats.iterateDays = function (data, callback) {
callback(cDay, start); callback(cDay, start);
start.add(1, "days"); start.add(1, "days");
} }
return GitStats;
}; };
/** /**
@ -165,7 +174,7 @@ GitStats.iterateDays = function (data, callback) {
* @function * @function
* @param {Object} data The object passed to the `iterateDays` method. * @param {Object} data The object passed to the `iterateDays` method.
* @param {Function} callback The callback function. * @param {Function} callback The callback function.
* @return {undefined} * @return {GitStats} The `GitStats` object.
*/ */
GitStats.graph = function (data, callback) { GitStats.graph = function (data, callback) {
@ -196,6 +205,8 @@ GitStats.graph = function (data, callback) {
callback(null, year); callback(null, year);
}); });
return GitStats;
}; };
/** /**
@ -206,7 +217,7 @@ GitStats.graph = function (data, callback) {
* @function * @function
* @param {Object} data The object passed to the `graph` method. * @param {Object} data The object passed to the `graph` method.
* @param {Function} callback The callback function. * @param {Function} callback The callback function.
* @return {undefined} * @return {GitStats} The `GitStats` object.
*/ */
GitStats.calendar = function (data, callback) { GitStats.calendar = function (data, callback) {
GitStats.graph(data, function (err, graph) { GitStats.graph(data, function (err, graph) {
@ -248,6 +259,7 @@ GitStats.calendar = function (data, callback) {
callback(null, cal); callback(null, cal);
}); });
return GitStats;
}; };
/** /**
@ -258,7 +270,7 @@ GitStats.calendar = function (data, callback) {
* @function * @function
* @param {Object} data The object passed to the `calendar` method. * @param {Object} data The object passed to the `calendar` method.
* @param {Function} callback The callback function. * @param {Function} callback The callback function.
* @return {undefined} * @return {GitStats} The `GitStats` object.
*/ */
GitStats.ansiCalendar = function (data, callback) { GitStats.ansiCalendar = function (data, callback) {
@ -352,4 +364,6 @@ GitStats.ansiCalendar = function (data, callback) {
callback(null, strYear); callback(null, strYear);
}); });
return GitStats;
}; };