summaryrefslogtreecommitdiffstats
path: root/lib/models/config.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/models/config.js')
-rw-r--r--lib/models/config.js47
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;