Permalink
Browse files

[fix] Rework helpers.defaultUser

- Use .indexOf instead of .search
- Rename appName to data. This can be used for more than just app names.
  • Loading branch information...
Southern committed Jul 24, 2013
1 parent fcbc2a8 commit 0fbaddeccf0d82c232b570c5d6212d8415f558c9
Showing with 12 additions and 8 deletions.
  1. +7 −3 node.js/lib/client/databases.js
  2. +5 −5 node.js/lib/client/helpers.js
@@ -8,6 +8,7 @@
*/

var util = require('util'),
defaultUser = require('./helpers').defaultUser,
Client = require('./client').Client;

//
@@ -31,7 +32,8 @@ util.inherits(Databases, Client);
// Provisions a database for the user
//
Databases.prototype.create = function (databaseType, databaseName, callback) {
var argv = ['databases', this.options.get('username'), databaseName];
databaseName = defaultUser.call(this, databaseName);
var argv = [ 'databases' ].concat(databaseName.split('/'));

this.request({ method: 'POST', uri: argv, body: { type: databaseType }}, function (err, result, res) {
if (err) return callback(err);
@@ -47,7 +49,8 @@ Databases.prototype.create = function (databaseType, databaseName, callback) {
// Gets the metadata for the specified database
//
Databases.prototype.get = function (databaseName, callback) {
var argv = ['databases', this.options.get('username'), databaseName];
databaseName = defaultUser.call(this, databaseName);
var argv = [ 'databases' ].concat(databaseName.split('/'));

this.request({ uri: argv }, function (err, result) {
if (err) return callback(err);
@@ -82,7 +85,8 @@ Databases.prototype.list = function (username, callback) {
// Deprovisions specified database
//
Databases.prototype.destroy = function (databaseName, callback) {
var argv = ['databases', this.options.get('username'), databaseName];
databaseName = defaultUser.call(this, databaseName);
var argv = [ 'databases' ].concat(databaseName.split('/'));

this.request({ method: 'DELETE', uri: argv }, callback);
};
@@ -2,17 +2,17 @@

//
// ### function defaultUser (appName)
// #### @appName {String} App name
// #### @data {String} App name, user/app, or user/database.
//
// A helper to prepend a default username.
// needs 'this' to be able to options.get('username').
//
exports.defaultUser = function (appName) {
if (appName.search('/') === -1) {
appName = this.options.get('username') + '/' + appName;
exports.defaultUser = function (data) {
if (!~data.indexOf('/')) {
data = this.options.get('username') + '/' + data;
}

return appName;
return data;
};

//

0 comments on commit 0fbadde

Please sign in to comment.