Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move hash functions to a separate file

  • Loading branch information...
commit a609ad9aee9209512380f03d30636a870da96464 1 parent 3e9573b
@dresende authored
Showing with 12 additions and 8 deletions.
  1. +8 −0 lib/hash.js
  2. +4 −8 lib/orm.js
View
8 lib/hash.js
@@ -0,0 +1,8 @@
+module.exports = {
+ hash: function (data) {
+ var h = require("crypto").createHash("md5");
+ h.update(JSON.stringify(data));
+
+ return h.digest("hex");
+ }
+}
View
12 lib/orm.js
@@ -104,20 +104,19 @@ ORM.prototype.define = function (model, fields, colParams) {
}
}
- var h = crypto.createHash("md5");
- h.update(JSON.stringify(data));
-
- this._dataHash = h.digest("hex");
+ this._dataHash = require("./hash").hash(data);
if (this._dataPending == 0) {
this.emit("ready", this);
}
};
+ // this adds events to instances
util.inherits(Model, events.EventEmitter);
associationHelpers.one = require("./associations/one").define(orm, Model, model, fields, colParams);
associationHelpers.many = require("./associations/many").define(orm, Model, model, fields, colParams);
+ // this adds events to object
require("./events").extend(Model);
Model.prototype._getData = function () {
@@ -180,10 +179,7 @@ ORM.prototype.define = function (model, fields, colParams) {
return (this._pending == 0);
};
Model.prototype.saved = function () {
- var h = crypto.createHash("md5");
- h.update(JSON.stringify(this._getData()));
-
- return (this._dataHash == h.digest("hex"));
+ return (this._dataHash == require("./hash").hash(this._getData()));
};
Model.prototype.created = function () {
return this.hasOwnProperty("id");
Please sign in to comment.
Something went wrong with that request. Please try again.