Add method "toText" to config

This commit is contained in:
Samy Pesse
2016-06-06 17:16:53 +02:00
parent f8676483c1
commit 29df73ba72
+53 -56
View File
@@ -19,21 +19,27 @@ Config.prototype.getValues = function() {
};
/**
Change the file for the configuration
* Render config as text
* @return {Promise<String>}
*/
Config.prototype.toText = function() {
return JSON.stringify(this.getValues().toJS(), null, 4);
};
@param {File} file
@return {Config}
*/
/**
* Change the file for the configuration
* @param {File} file
* @return {Config}
*/
Config.prototype.setFile = function(file) {
return this.set('file', file);
};
/**
Return a configuration value by its key path
@param {String} key
@return {Mixed}
*/
* Return a configuration value by its key path
* @param {String} key
* @return {Mixed}
*/
Config.prototype.getValue = function(keyPath, def) {
var values = this.getValues();
keyPath = Config.keyToKeyPath(keyPath);
@@ -46,12 +52,11 @@ Config.prototype.getValue = function(keyPath, def) {
};
/**
Update a configuration value
@param {String} key
@param {Mixed} value
@return {Config}
*/
* Update a configuration value
* @param {String} key
* @param {Mixed} value
* @return {Config}
*/
Config.prototype.setValue = function(keyPath, value) {
keyPath = Config.keyToKeyPath(keyPath);
@@ -64,10 +69,9 @@ Config.prototype.setValue = function(keyPath, value) {
};
/**
Return a list of plugin dependencies
@return {List<PluginDependency>}
*/
* Return a list of plugin dependencies
* @return {List<PluginDependency>}
*/
Config.prototype.getPluginDependencies = function() {
var plugins = this.getValue('plugins');
@@ -79,11 +83,10 @@ Config.prototype.getPluginDependencies = function() {
};
/**
Return a plugin dependency by its name
@param {String} name
@return {PluginDependency}
*/
* Return a plugin dependency by its name
* @param {String} name
* @return {PluginDependency}
*/
Config.prototype.getPluginDependency = function(name) {
var plugins = this.getPluginDependencies();
@@ -93,11 +96,10 @@ Config.prototype.getPluginDependency = function(name) {
};
/**
Update the list of plugins dependencies
@param {List<PluginDependency>}
@return {Config}
*/
* Update the list of plugins dependencies
* @param {List<PluginDependency>}
* @return {Config}
*/
Config.prototype.setPluginDependencies = function(deps) {
var plugins = PluginDependency.listToArray(deps);
@@ -106,11 +108,10 @@ Config.prototype.setPluginDependencies = function(deps) {
/**
Update values for an existing configuration
@param {Object} values
@returns {Config}
*/
* Update values for an existing configuration
* @param {Object} values
* @returns {Config}
*/
Config.prototype.updateValues = function(values) {
values = Immutable.fromJS(values);
@@ -118,12 +119,11 @@ Config.prototype.updateValues = function(values) {
};
/**
Update values for an existing configuration
@param {Config} config
@param {Object} values
@returns {Config}
*/
* Update values for an existing configuration
* @param {Config} config
* @param {Object} values
* @returns {Config}
*/
Config.prototype.mergeValues = function(values) {
var currentValues = this.getValues();
values = Immutable.fromJS(values);
@@ -134,12 +134,11 @@ Config.prototype.mergeValues = function(values) {
};
/**
Create a new config for a file
@param {File} file
@param {Object} values
@returns {Config}
*/
* Create a new config for a file
* @param {File} file
* @param {Object} values
* @returns {Config}
*/
Config.create = function(file, values) {
return new Config({
file: file,
@@ -148,11 +147,10 @@ Config.create = function(file, values) {
};
/**
Create a new config
@param {Object} values
@returns {Config}
*/
* Create a new config
* @param {Object} values
* @returns {Config}
*/
Config.createWithValues = function(values) {
return new Config({
values: Immutable.fromJS(values)
@@ -161,11 +159,10 @@ Config.createWithValues = function(values) {
/**
Convert a keyPath to an array of keys
@param {String|Array}
@return {Array}
*/
* Convert a keyPath to an array of keys
* @param {String|Array}
* @return {Array}
*/
Config.keyToKeyPath = function(keyPath) {
if (is.string(keyPath)) keyPath = keyPath.split('.');
return keyPath;