Permalink
Browse files

[confirm] use resourceful.autoMigrate instead of callbacks

  • Loading branch information...
1 parent 59f912c commit a94ce66e603ee8ab5b2cb44157c3ce4f112a7912 @indutny indutny committed Oct 7, 2011
View
@@ -5,6 +5,7 @@ var sys = require('sys'),
var resourceful = exports;
resourceful.env = 'development';
+resourceful.autoMigrate = true;
resourceful.resources = {};
resourceful.Resource = require('./resource').Resource;
resourceful.engines = require('./engines');
@@ -166,34 +166,31 @@ Connection.prototype.sync = function (factory, callback) {
}
// Request confirmation
- callback(null, factory._design, function(err, agreed, callback) {
- callback || (callback = function() {});
-
- if (err || !agreed) {
- return callback(err || 'You should confirm design doc update');
- }
+ if (!resourceful.autoMigrate) {
+ return callback(Error('resourceful.autoMigrate should be set to true ' +
+ 'to allow migrations'));
+ }
- that.connection.put(id, factory._design, function (e, res) {
- if (e) {
- if (e.reason === 'no_db_file') {
- that.connection.connection.create(function () {
- that.sync(callback);
- });
- } else {
- /* TODO: Catch errors here. Needs a rewrite, because of the race */
- /* condition, when the design doc is trying to be written in parallel */
- callback(e);
- }
- }
- else {
- // We might not need to wait for the document to be
- // persisted, before returning it. If for whatever reason
- // the insert fails, it'll just re-attempt it. For now though,
- // to be on the safe side, we wait.
- factory._design._rev = res.rev;
- callback(null, factory._design);
+ that.connection.put(id, factory._design, function (e, res) {
+ if (e) {
+ if (e.reason === 'no_db_file') {
+ that.connection.connection.create(function () {
+ that.sync(callback);
+ });
+ } else {
+ /* TODO: Catch errors here. Needs a rewrite, because of the race */
+ /* condition, when the design doc is trying to be written in parallel */
+ callback(e);
}
- });
+ }
+ else {
+ // We might not need to wait for the document to be
+ // persisted, before returning it. If for whatever reason
+ // the insert fails, it'll just re-attempt it. For now though,
+ // to be on the safe side, we wait.
+ factory._design._rev = res.rev;
+ callback(null, factory._design);
+ }
});
});
}
@@ -82,7 +82,8 @@ exports.filter = function (name /* [options], filter */) {
if (R._design._rev) {
that.view(path, params, callback);
} else {
- R.sync(function () {
+ R.sync(function (err) {
+ if (err) return callback(err);
that.view(path, params, callback);
});
}
@@ -461,28 +461,23 @@ Resource.sync = function (callback) {
var that = this,
id = ["_design", this.resource].join('/');
- this.once('sync', function (d, confirm) {
- callback && callback(null, d, confirm);
+ this.once('sync', function (d) {
+ callback && callback(null, d);
});
if (this._synching) {
return;
}
this._synching = true;
- this.connection.sync(this, function (e, design, confirm) {
+ this.connection.sync(this, function (e, design) {
+ if (e) {
+ // XXX how to report errors here?
+ this.emit('error', e);
+ }
that._synching = false;
- // Ensure that confirmation callback will be called only once
- var once = false;
- that.emit('sync', design, confirm && function(err, agreed) {
- if (once) return;
- once = true;
-
- // Engine may not implement confirmation callback
- // Ignore calls to this function if so
- confirm(err, agreed);
- });
+ that.emit('sync', design);
});
};

0 comments on commit a94ce66

Please sign in to comment.