Skip to content

Commit

Permalink
[minor] Fix whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
pksunkara committed Apr 14, 2012
1 parent 0dc93f7 commit ff36dba
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions lib/resourceful/cache.js
Expand Up @@ -27,7 +27,7 @@ exports.Cache.prototype.get = function (id) {
return id.map(function (k) {
return that.store[k.toString()];
});
}
}
else {
return this.store[id.toString()];
}
Expand All @@ -54,7 +54,7 @@ exports.Cache.prototype.clear = function (id) {
if (id) {
this.size --;
delete(this.store[id]);
}
}
else {
this.size = 0;
this.store = {};
Expand Down
4 changes: 2 additions & 2 deletions lib/resourceful/definers.js
Expand Up @@ -163,9 +163,9 @@ module.exports = {
}),
prefix: function (prefix) {
var matcher = new RegExp('^' + prefix + '(.*)');

return this.sanitize(function (val) {
return !matcher.test(val)
return !matcher.test(val)
? prefix + val
: val;
});
Expand Down
26 changes: 13 additions & 13 deletions lib/resourceful/engines/couchdb/index.js
Expand Up @@ -28,7 +28,7 @@ var Couchdb = exports.Couchdb = function Couchdb(config) {
secure: config.secure,
auth: config && config.auth || null
}).database(config.database || resourceful.env);

this.cache = new resourceful.Cache();
};

Expand All @@ -53,8 +53,8 @@ Couchdb.prototype.get = function (id, callback) {
e.status = e.headers.status;
return callback(e);
}
return Array.isArray(id)

return Array.isArray(id)
? callback(null, res.rows.map(function (r) { return r.doc; }))
: callback(null, res);
});
Expand All @@ -63,7 +63,7 @@ Couchdb.prototype.get = function (id, callback) {
Couchdb.prototype.put = function (id, doc, callback) {
return this.request('put', id, doc, function (e, res) {
if (e) return callback(e);

res.status = 201;
callback(null, resourceful.mixin({}, doc, res));
});
Expand All @@ -82,12 +82,12 @@ Couchdb.prototype.save = function (id, doc, callback) {
var args = Array.prototype.slice.call(arguments, 0),
callback = args.pop(),
doc = args.pop();

// if there's an ID left in args after popping off the callback and
// the doc, then we need to PUT, otherwise create a new record thru POST
if (args.length) {
return this.put.apply(this, arguments);
}
}

// checks for presence of _id in doc, just in case the caller forgot
// to add an id as first argument
Expand All @@ -98,7 +98,7 @@ Couchdb.prototype.save = function (id, doc, callback) {
}
};
Couchdb.prototype.update = function (id, doc, callback) {
return this.cache.has(id)
return this.cache.has(id)
? this.put(id, resourceful.mixin({}, this.cache.get(id).toJSON(), doc), callback)
: this.request('merge', id, doc, callback);
};
Expand All @@ -116,17 +116,17 @@ Couchdb.prototype.destroy = function () {

if (rev) {
return this.request.apply(this, ['remove', id, rev, callback]);
}
}
if (this.cache.has(id)) {
args.splice(1, -1, this.cache.get(id)._rev);
return this.request.apply(this, ['remove'].concat(args));
}
}

this.head(id, function (e, headers, res) {
if (res === 404 || !headers['etag']) {
e = e || { reason: 'not_found' };
}

if (headers.etag) {
args.splice(1, -1, headers.etag.slice(1, -1));
return that.request.apply(that, ['remove'].concat(args));
Expand Down Expand Up @@ -176,14 +176,14 @@ Couchdb.prototype.sync = function (factory, callback) {
if (!e && headers.etag) {
factory._design._rev = headers.etag.slice(1, -1);
}

that.connection.put(id, factory._design, function (e, res) {
if (e) {
if (e.reason === 'no_db_file') {
that.connection.create(function () {
that.sync(factory, callback);
});
}
}
else {

/* TODO: Catch errors here. Needs a rewrite, because of the race */
Expand Down
2 changes: 1 addition & 1 deletion lib/resourceful/engines/memory.js
Expand Up @@ -9,7 +9,7 @@ var Memory = exports.Memory = function (options) {
var counter = 0;
options = options || {};
this.uri = options.uri;

this.increment = function () {
return ++counter;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/resourceful/init.js
Expand Up @@ -3,7 +3,7 @@ module.exports = function init(obj, property, schema) {
if (obj[property]) {
return obj[property];
}

return !!init.type[schema.type]
? init.type[schema.type](schema)
: null;
Expand Down
20 changes: 10 additions & 10 deletions lib/resourceful/resource.js
Expand Up @@ -8,10 +8,10 @@ var util = require('util'),
//
var Resource = exports.Resource = function () {
Object.defineProperty(this, 'isNewRecord', {
value: true,
value: true,
writable: true
});

Object.defineProperty(this, 'schema', {
value: this.constructor.schema,
enumerable: false,
Expand Down Expand Up @@ -175,7 +175,7 @@ Resource.get = function (id, callback) {
id = this.schema.properties._id.sanitize(id);
}

return id
return id
? this._request('get', id, callback)
: callback && callback(new Error('key is undefined'));
};
Expand Down Expand Up @@ -245,8 +245,8 @@ Resource.destroy = function (id, callback) {
if (this.schema.properties._id && this.schema.properties._id.sanitize) {
id = this.schema.properties._id.sanitize(id);
}
return id

return id
? this._request('destroy', id, callback)
: callback && callback(new Error('key is undefined'));
};
Expand All @@ -255,12 +255,12 @@ Resource.update = function (id, obj, callback) {
if (this.schema.properties._id && this.schema.properties._id.sanitize) {
id = this.schema.properties._id.sanitize(id);
}

if (this._timestamps) {
obj.mtime = Date.now();
}
return id

return id
? this._request('update', id, obj, callback)
: callback && callback(new Error('key is undefined'));
};
Expand Down Expand Up @@ -610,7 +610,7 @@ Resource.prototype.update = function (obj, callback) {

Resource.prototype.saveAttachment = function (attachment, callback) {
return this.constructor.saveAttachment({
id: this._id,
id: this._id,
rev: this._rev
}, attachment, callback);
};
Expand Down Expand Up @@ -659,7 +659,7 @@ Resource.prototype.__defineGetter__('key', function () {
});

Resource.prototype.__defineGetter__('id', function () {
return this.constructor.key === '_id'
return this.constructor.key === '_id'
? this._id
: undefined;
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -16,7 +16,7 @@
},
"dependencies": {
"cradle": "0.6.x",
"revalidator": "0.1.x"
"revalidator": "0.1.x"
},
"devDependencies": {
"vows": "~0.6.0"
Expand Down

0 comments on commit ff36dba

Please sign in to comment.