diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-04-22 11:00:21 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-04-22 11:00:21 +0200 |
commit | 4336fdb2414d460ffee68a0cc87c0cb0c85cf56e (patch) | |
tree | 279f711ab98666c892c19a7b9e4073a094f03f98 /lib/models/config.js | |
parent | 87db7cf1d412fa6fbd18e9a7e4f4755f2c0c5547 (diff) | |
download | gitbook-4336fdb2414d460ffee68a0cc87c0cb0c85cf56e.zip gitbook-4336fdb2414d460ffee68a0cc87c0cb0c85cf56e.tar.gz gitbook-4336fdb2414d460ffee68a0cc87c0cb0c85cf56e.tar.bz2 |
Base
Diffstat (limited to 'lib/models/config.js')
-rw-r--r-- | lib/models/config.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/models/config.js b/lib/models/config.js new file mode 100644 index 0000000..fd4201d --- /dev/null +++ b/lib/models/config.js @@ -0,0 +1,47 @@ +var is = require('is'); +var Immutable = require('immutable'); + +var File = require('./file'); + +var Config = Immutable.Record({ + file: File(), + values: Immutable.Map() +}); + +Config.prototype.getPath = function() { + return this.get('path'); +}; + +Config.prototype.getValues = function() { + return this.get('values'); +}; + +/** + Return a configuration value by its key path + + @param {String} key + @return {Mixed} +*/ +Config.prototype.getValue = function(keyPath, def) { + var values = this.getValues(); + if (is.string(keyPath)) keyPath = keyPath.split('.'); + + return values.getIn(keyPath) || def; +}; + +/** + Create a new config, throw error if invalid + + @param {File} file + @param {Object} values + @returns {Config} +*/ +Config.create = function(file, values) { + return new Config({ + file: file, + values: Immutable.fromJS(values) + }); +}; + + +module.exports = Config; |