Ghost/core/shared/models/dataProvider.bookshelf.settings.js
2013-05-30 23:34:53 +01:00

37 lines
1.1 KiB
JavaScript

(function () {
"use strict";
var _ = require('underscore'),
when = require('when'),
util = require('util'),
models = require('./models'),
BaseProvider = require('./dataProvider.bookshelf.base'),
SettingsProvider;
/**
* The Posts data provider implementation for Bookshelf.
*/
SettingsProvider = function () {
BaseProvider.call(this, models.Setting, models.Settings);
};
util.inherits(SettingsProvider, BaseProvider);
SettingsProvider.prototype.read = function (_key) {
// Allow for just passing the key instead of attributes
if (_.isString(_key)) {
_key = { key: _key };
}
return BaseProvider.prototype.read.call(this, _key);
};
SettingsProvider.prototype.edit = function (_data) {
return when.all(_.map(_data, function (value, key) {
return this.model.forge({ key: key }).fetch().then(function (setting) {
return setting.set('value', value).save();
});
}, this));
};
module.exports = SettingsProvider;
}());