From 0922563593bb09073d07082dd3ae6462883884c0 Mon Sep 17 00:00:00 2001 From: indexzero Date: Sun, 20 Sep 2015 01:37:09 -0700 Subject: [PATCH] [doc fix] Remove unused and outdated literate coding documentation. --- docs/docco.css | 194 ----------------- docs/nconf.html | 20 -- docs/nconf/common.html | 85 -------- docs/nconf/formats.html | 22 -- docs/nconf/provider.html | 378 ---------------------------------- docs/nconf/stores.html | 19 -- docs/nconf/stores/file.html | 170 --------------- docs/nconf/stores/memory.html | 143 ------------- docs/nconf/stores/system.html | 98 --------- 9 files changed, 1129 deletions(-) delete mode 100644 docs/docco.css delete mode 100644 docs/nconf.html delete mode 100644 docs/nconf/common.html delete mode 100644 docs/nconf/formats.html delete mode 100644 docs/nconf/provider.html delete mode 100644 docs/nconf/stores.html delete mode 100644 docs/nconf/stores/file.html delete mode 100644 docs/nconf/stores/memory.html delete mode 100644 docs/nconf/stores/system.html diff --git a/docs/docco.css b/docs/docco.css deleted file mode 100644 index bd54134..0000000 --- a/docs/docco.css +++ /dev/null @@ -1,194 +0,0 @@ -/*--------------------- Layout and Typography ----------------------------*/ -body { - font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif; - font-size: 15px; - line-height: 22px; - color: #252519; - margin: 0; padding: 0; -} -a { - color: #261a3b; -} - a:visited { - color: #261a3b; - } -p { - margin: 0 0 15px 0; -} -h4, h5, h6 { - color: #333; - margin: 6px 0 6px 0; - font-size: 13px; -} - h2, h3 { - margin-bottom: 0; - color: #000; - } - h1 { - margin-top: 40px; - margin-bottom: 15px; - color: #000; - } -#container { - position: relative; -} -#background { - position: fixed; - top: 0; left: 525px; right: 0; bottom: 0; - background: #f5f5ff; - border-left: 1px solid #e5e5ee; - z-index: -1; -} -#jump_to, #jump_page { - background: white; - -webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777; - -webkit-border-bottom-left-radius: 5px; -moz-border-radius-bottomleft: 5px; - font: 10px Arial; - text-transform: uppercase; - cursor: pointer; - text-align: right; -} -#jump_to, #jump_wrapper { - position: fixed; - right: 0; top: 0; - padding: 5px 10px; -} - #jump_wrapper { - padding: 0; - display: none; - } - #jump_to:hover #jump_wrapper { - display: block; - } - #jump_page { - padding: 5px 0 3px; - margin: 0 0 25px 25px; - } - #jump_page .source { - display: block; - padding: 5px 10px; - text-decoration: none; - border-top: 1px solid #eee; - } - #jump_page .source:hover { - background: #f5f5ff; - } - #jump_page .source:first-child { - } -table td { - border: 0; - outline: 0; -} - td.docs, th.docs { - max-width: 450px; - min-width: 450px; - min-height: 5px; - padding: 10px 25px 1px 50px; - overflow-x: hidden; - vertical-align: top; - text-align: left; - } - .docs pre { - margin: 15px 0 15px; - padding-left: 15px; - } - .docs p tt, .docs p code { - background: #f8f8ff; - border: 1px solid #dedede; - font-size: 12px; - padding: 0 0.2em; - } - .pilwrap { - position: relative; - } - .pilcrow { - font: 12px Arial; - text-decoration: none; - color: #454545; - position: absolute; - top: 3px; left: -20px; - padding: 1px 2px; - opacity: 0; - -webkit-transition: opacity 0.2s linear; - } - td.docs:hover .pilcrow { - opacity: 1; - } - td.code, th.code { - padding: 14px 15px 16px 25px; - width: 100%; - vertical-align: top; - background: #f5f5ff; - border-left: 1px solid #e5e5ee; - } - pre, tt, code { - font-size: 12px; line-height: 18px; - font-family: Menlo, Monaco, Consolas, "Lucida Console", monospace; - margin: 0; padding: 0; - } - - -/*---------------------- Syntax Highlighting -----------------------------*/ -td.linenos { background-color: #f0f0f0; padding-right: 10px; } -span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; } -body .hll { background-color: #ffffcc } -body .c { color: #408080; font-style: italic } /* Comment */ -body .err { border: 1px solid #FF0000 } /* Error */ -body .k { color: #954121 } /* Keyword */ -body .o { color: #666666 } /* Operator */ -body .cm { color: #408080; font-style: italic } /* Comment.Multiline */ -body .cp { color: #BC7A00 } /* Comment.Preproc */ -body .c1 { color: #408080; font-style: italic } /* Comment.Single */ -body .cs { color: #408080; font-style: italic } /* Comment.Special */ -body .gd { color: #A00000 } /* Generic.Deleted */ -body .ge { font-style: italic } /* Generic.Emph */ -body .gr { color: #FF0000 } /* Generic.Error */ -body .gh { color: #000080; font-weight: bold } /* Generic.Heading */ -body .gi { color: #00A000 } /* Generic.Inserted */ -body .go { color: #808080 } /* Generic.Output */ -body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */ -body .gs { font-weight: bold } /* Generic.Strong */ -body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ -body .gt { color: #0040D0 } /* Generic.Traceback */ -body .kc { color: #954121 } /* Keyword.Constant */ -body .kd { color: #954121; font-weight: bold } /* Keyword.Declaration */ -body .kn { color: #954121; font-weight: bold } /* Keyword.Namespace */ -body .kp { color: #954121 } /* Keyword.Pseudo */ -body .kr { color: #954121; font-weight: bold } /* Keyword.Reserved */ -body .kt { color: #B00040 } /* Keyword.Type */ -body .m { color: #666666 } /* Literal.Number */ -body .s { color: #219161 } /* Literal.String */ -body .na { color: #7D9029 } /* Name.Attribute */ -body .nb { color: #954121 } /* Name.Builtin */ -body .nc { color: #0000FF; font-weight: bold } /* Name.Class */ -body .no { color: #880000 } /* Name.Constant */ -body .nd { color: #AA22FF } /* Name.Decorator */ -body .ni { color: #999999; font-weight: bold } /* Name.Entity */ -body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */ -body .nf { color: #0000FF } /* Name.Function */ -body .nl { color: #A0A000 } /* Name.Label */ -body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */ -body .nt { color: #954121; font-weight: bold } /* Name.Tag */ -body .nv { color: #19469D } /* Name.Variable */ -body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */ -body .w { color: #bbbbbb } /* Text.Whitespace */ -body .mf { color: #666666 } /* Literal.Number.Float */ -body .mh { color: #666666 } /* Literal.Number.Hex */ -body .mi { color: #666666 } /* Literal.Number.Integer */ -body .mo { color: #666666 } /* Literal.Number.Oct */ -body .sb { color: #219161 } /* Literal.String.Backtick */ -body .sc { color: #219161 } /* Literal.String.Char */ -body .sd { color: #219161; font-style: italic } /* Literal.String.Doc */ -body .s2 { color: #219161 } /* Literal.String.Double */ -body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */ -body .sh { color: #219161 } /* Literal.String.Heredoc */ -body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */ -body .sx { color: #954121 } /* Literal.String.Other */ -body .sr { color: #BB6688 } /* Literal.String.Regex */ -body .s1 { color: #219161 } /* Literal.String.Single */ -body .ss { color: #19469D } /* Literal.String.Symbol */ -body .bp { color: #954121 } /* Name.Builtin.Pseudo */ -body .vc { color: #19469D } /* Name.Variable.Class */ -body .vg { color: #19469D } /* Name.Variable.Global */ -body .vi { color: #19469D } /* Name.Variable.Instance */ -body .il { color: #666666 } /* Literal.Number.Integer.Long */ \ No newline at end of file diff --git a/docs/nconf.html b/docs/nconf.html deleted file mode 100644 index cb9a1f9..0000000 --- a/docs/nconf.html +++ /dev/null @@ -1,20 +0,0 @@ - nconf.js

nconf.js

/*
- * nconf.js: Top-level include for the nconf module
- *
- * (C) 2011, Charlie Robbins
- *
- */
-
-var fs = require('fs'),
-    async = require('async'),
-    common = require('./nconf/common'),
-    Provider = require('./nconf/provider').Provider,
-    nconf = module.exports = new Provider();

Expose the version from the package.json using pkginfo.

require('pkginfo')(module, 'version');

Expose the various components included with nconf

nconf.key           = common.key;
-nconf.path          = common.path;
-nconf.loadFiles     = common.loadFiles;
-nconf.loadFilesSync = common.loadFilesSync;
-nconf.formats       = require('./nconf/formats');
-nconf.stores        = require('./nconf/stores');
-nconf.Provider      = Provider;
-
-
\ No newline at end of file diff --git a/docs/nconf/common.html b/docs/nconf/common.html deleted file mode 100644 index 5c359ce..0000000 --- a/docs/nconf/common.html +++ /dev/null @@ -1,85 +0,0 @@ - common.js

common.js

/*
- * utils.js: Utility functions for the nconf module.
- *
- * (C) 2011, Charlie Robbins
- *
- */
- 
-var fs = require('fs'),
-    async = require('async'),
-    formats = require('./formats'),
-    Memory = require('./stores/Memory').Memory;
-
-var common = exports;

function path (key)

- -

@key {string} The ':' delimited key to split

- -

Returns a fully-qualified path to a nested nconf key.

common.path = function (key) {
-  return key.split(':');
-};

function key (arguments)

- -

Returns a : joined string from the arguments.

common.key = function () {
-  return Array.prototype.slice.call(arguments).join(':');
-};

function loadFiles (files, callback)

- -

@files {Object|Array} List of files (or settings object) to load.

- -

@callback {function} Continuation to respond to when complete.

- -

Loads all the data in the specified files.

common.loadFiles = function (files, callback) {
-  if (!files) {
-    return callback(null, {});
-  }
-
-  var options = Array.isArray(files) ? { files: files } : files;

Set the default JSON format if not already -specified

  options.format = options.format || formats.json;
-
-  function parseFile (file, next) {
-    fs.readFile(file, function (err, data) {
-      return !err 
-        ? next(null, options.format.parse(data.toString()))
-        : next(err);
-    });
-  }
-
-  async.map(files, parseFile, function (err, objs) {
-    return err ? callback(err) : callback(null, common.merge(objs));
-  });
-};

function loadFilesSync (files)

- -

@files {Object|Array} List of files (or settings object) to load.

- -

Loads all the data in the specified files synchronously.

common.loadFilesSync = function (files) {
-  if (!files) {
-    return;
-  }

Set the default JSON format if not already -specified

  var options = Array.isArray(files) ? { files: files } : files;
-  options.format = options.format || formats.json;
-
-  return common.merge(files.map(function (file) {
-    return options.format.parse(fs.readFileSync(file, 'utf8'));
-  }));
-};

function merge (objs)

- -

@objs {Array} Array of object literals to merge

- -

Merges the specified objs using a temporary instance -of stores.Memory.

common.merge = function (objs) {
-  var store = new Memory();
-  
-  objs.forEach(function (obj) {
-    Object.keys(obj).forEach(function (key) {
-      store.merge(key, obj[key]);
-    });
-  });
-  
-  return store.store;
-};

function capitalize (str)

- -

@str {string} String to capitalize

- -

Capitalizes the specified str.

common.capitalize = function (str) {
-  return str && str[0].toUpperCase() + str.slice(1);
-};
-
-
\ No newline at end of file diff --git a/docs/nconf/formats.html b/docs/nconf/formats.html deleted file mode 100644 index a2ab2f5..0000000 --- a/docs/nconf/formats.html +++ /dev/null @@ -1,22 +0,0 @@ - formats.js

formats.js

/*
- * formats.js: Default formats supported by nconf
- *
- * (C) 2011, Charlie Robbins
- *
- */
-
-var ini = require('ini');
-
-var formats = exports;

@json

- -

Standard JSON format which pretty prints .stringify().

formats.json = {
-  stringify: function (obj) {
-    return JSON.stringify(obj, null, 2)
-  },
-  parse: JSON.parse
-};

@ini

- -

Standard INI format supplied from the ini module -http://en.wikipedia.org/wiki/INI_file

formats.ini = ini;
-
-
\ No newline at end of file diff --git a/docs/nconf/provider.html b/docs/nconf/provider.html deleted file mode 100644 index b349626..0000000 --- a/docs/nconf/provider.html +++ /dev/null @@ -1,378 +0,0 @@ - provider.js

provider.js

/*
- * provider.js: Abstraction providing an interface into pluggable configuration storage.
- *
- * (C) 2011, Charlie Robbins
- *
- */
-
-var async = require('async'),
-    common = require('./common'),
-    stores = require('./stores');

function Provider (options)

- -

@options {Object} Options for this instance.

- -

Constructor function for the Provider object responsible -for exposing the pluggable storage features of nconf.

var Provider = exports.Provider = function (options) {
-  var self = this;
-  

Setup default options for working with stores, -overrides, process.env and process.argv.

  options         = options           || {};
-  this._overrides = options.overrides || null;
-  this._argv      = options.argv      || false;
-  this._env       = options.env       || false;
-  this._reserved  = Object.keys(Provider.prototype);
-  this._stores    = [];
-  

Add the default system store for working with -overrides, process.env, process.argv and -a simple in-memory objects.

  this.add('system', options);
-
-  if (options.type) {
-    this.add(options.type, options);
-  }
-  else if (options.store) {
-    this.add(options.store.name || options.store.type, options.store);
-  }
-  else if (options.stores) {
-    Object.keys(options.stores).forEach(function (store) {
-      self.add(store.name || store.type, store);
-    });
-  }
-};

function use (name, options)

- -

@type {string} Type of the nconf store to use.

- -

@options {Object} Options for the store instance.

- -

Adds (or replaces) a new store with the specified name -and options. If options.type is not set, then name -will be used instead:

- -

provider.use('file'); - provider.use('file', { type: 'file', filename: '/path/to/userconf' })

Provider.prototype.use = function (name, options) {
-  if (name === 'system') {
-    return;
-  }
-  else if (this._reserved.indexOf(name) !== -1) {
-    throw new Error('Cannot use reserved name: ' + name);
-  }
-
-  options  = options      || {};
-  var type = options.type || name;
-
-  function sameOptions (store) {
-    return Object.keys(options).every(function (key) {
-      return options[key] === store[key];
-    });
-  }
-
-  var store = this[name],
-      update = store && !sameOptions(store);
-
-  if (!store || update) {
-    if (update) {
-      this.remove(name);
-    }
-
-    this.add(name, options);
-  }
-
-  return this;
-};

function add (name, options)

- -

@name {string} Name of the store to add to this instance

- -

@options {Object} Options for the store to create

- -

Adds a new store with the specified name and options. If options.type -is not set, then name will be used instead:

- -

provider.add('memory'); - provider.add('userconf', { type: 'file', filename: '/path/to/userconf' })

Provider.prototype.add = function (name, options) {
-  if (this._reserved.indexOf(name) !== -1) {
-    throw new Error('Cannot use reserved name: ' + name);
-  }
-
-  options  = options      || {};
-  var type = options.type || name;
-
-  if (Object.keys(stores).indexOf(common.capitalize(type)) === -1) {
-    throw new Error('Cannot add store with unknown type: ' + type);
-  }
-
-  this[name] = this.create(type, options);
-  this._stores.push(name);
-
-  if (this[name].loadSync) {
-    this[name].loadSync();
-  }
-};

function remove (name)

- -

@name {string} Name of the store to remove from this instance

- -

Removes a store with the specified name from this instance. Users -are allowed to pass in a type argument (e.g. memory) as name if -this was used in the call to .add().

Provider.prototype.remove = function (name) {
-  if (this._reserved.indexOf(name) !== -1) {
-    throw new Error('Cannot use reserved name: ' + name);
-  }
-  else if (!this[name]) {
-    throw new Error('Cannot remove store that does not exist: ' + name);
-  }
-
-  delete this[name];
-  this._stores.splice(this._stores.indexOf(name), 1);
-};

function create (type, options)

- -

@type {string} Type of the nconf store to use.

- -

@options {Object} Options for the store instance.

- -

Creates a store of the specified type using the -specified options.

Provider.prototype.create = function (type, options) {
-  return new stores[common.capitalize(type.toLowerCase())](options);
-};

function get (key, callback)

- -

@key {string} Key to retrieve for this instance.

- -

@callback {function} Optional Continuation to respond to when complete.

- -

Retrieves the value for the specified key (if any).

Provider.prototype.get = function (key, callback) {

If there is no callback we can short-circuit into the default -logic for traversing stores.

  if (!callback) {
-    return this._execute('get', 1, key, callback);
-  }
-  

Otherwise the asynchronous, hierarchical get is -slightly more complicated because we do not need to traverse -the entire set of stores, but up until there is a defined value.

  var current = 0,
-      self = this,
-      response;
-
-  async.whilst(function () {
-    return typeof response === 'undefined' && current < self._stores.length;
-  }, function (next) {
-    var store = self[self._stores[current]];
-    current++;
-
-    if (store.get.length >= 2) {
-      return store.get(key, function (err, value) {
-        if (err) {
-          return next(err);
-        }
-
-        response = value;
-        next();
-      });
-    }
-
-    response = store.get(key);
-    next();
-  }, function (err) {
-    return err ? callback(err) : callback(null, response);
-  });
-};

function set (key, value, callback)

- -

@key {string} Key to set in this instance

- -

@value {literal|Object} Value for the specified key

- -

@callback {function} Optional Continuation to respond to when complete.

- -

Sets the value for the specified key in this instance.

Provider.prototype.set = function (key, value, callback) {
-  return this._execute('set', 2, key, value, callback);
-};

function reset (callback)

- -

@callback {function} Optional Continuation to respond to when complete.

- -

Clears all keys associated with this instance.

Provider.prototype.reset = function (callback) {
-  return this._execute('reset', 0, callback);
-};

function clear (key, callback)

- -

@key {string} Key to remove from this instance

- -

@callback {function} Optional Continuation to respond to when complete.

- -

Removes the value for the specified key from this instance.

Provider.prototype.clear = function (key, callback) {
-  return this._execute('clear', 1, key, callback);
-};

function merge ([key,] value [, callback])

- -

@key {string} Key to merge the value into

- -

@value {literal|Object} Value to merge into the key

- -

@callback {function} Optional Continuation to respond to when complete.

- -

Merges the properties in value into the existing object value at key.

- -
    -
  1. If the existing value key is not an Object, it will be completely overwritten.
  2. -
  3. If key is not supplied, then the value will be merged into the root.
  4. -
Provider.prototype.merge = function () {
-  var self = this,
-      args = Array.prototype.slice.call(arguments),
-      callback = typeof args[args.length - 1] === 'function' && args.pop(),
-      value = args.pop(),
-      key = args.pop();
-
-  function mergeProperty (prop, next) {
-    return self._execute('merge', 2, prop, value[prop], next);
-  }
-
-  if (!key) {
-    if (Array.isArray(value) || typeof value !== 'object') {
-      return onError(new Error('Cannot merge non-Object into top-level.'), callback);
-    }
-
-    return async.forEach(Object.keys(value), mergeProperty, callback || function () { })
-  }
-
-  return this._execute('merge', 2, key, value, callback);
-};

function load (callback)

- -

@callback {function} Continuation to respond to when complete.

- -

Responds with an Object representing all keys associated in this instance.

Provider.prototype.load = function (callback) {
-  var self = this;
-
-  function loadStoreSync(name) {
-    var store = self[name];
-
-    if (!store.loadSync) {
-      throw new Error('nconf store ' + store.type + ' has no loadSync() method');
-    }
-
-    return store.loadSync();
-  }
-
-  function loadStore(name, next) {
-    var store = self[name];
-
-    if (!store.load && !store.loadSync) {
-      return next(new Error('nconf store ' + store.type + ' has no load() method'));
-    }
-
-    return store.loadSync
-      ? next(null, store.loadSync())
-      : store.load(next);
-  }
-  

If we don't have a callback and the current -store is capable of loading synchronously -then do so.

  if (!callback) {
-    return common.merge(this._stores.map(loadStoreSync));
-  }
-
-  async.map(this._stores, loadStore, function (err, objs) {
-    return err ? callback(err) : callback(null, common.merge(objs));
-  });
-};

function save (value, callback)

- -

@value {Object} Optional Config object to set for this instance

- -

@callback {function} Continuation to respond to when complete.

- -

Removes any existing configuration settings that may exist in this -instance and then adds all key-value pairs in value.

Provider.prototype.save = function (value, callback) {
-  if (!callback && typeof value === 'function') {
-    callback = value;
-    value = null;
-  }
-
-  var self = this;
-
-  function saveStoreSync(name) {
-    var store = self[name];
-
-    if (!store.saveSync) {
-      throw new Error('nconf store ' + store.type + ' has no saveSync() method');
-    }
-
-    return store.saveSync();
-  }
-
-  function saveStore(name, next) {
-    var store = self[name];
-
-    if (!store.save && !store.saveSync) {
-      return next(new Error('nconf store ' + store.type + ' has no save() method'));
-    }
-
-    return store.saveSync
-      ? next(null, store.saveSync())
-      : store.save(next);
-  }
-  

If we don't have a callback and the current -store is capable of saving synchronously -then do so.

  if (!callback) {
-    return common.merge(this._stores.map(saveStoreSync));
-  }
-
-  async.map(this._stores, saveStore, function (err, objs) {
-    return err ? callback(err) : callback();
-  });
-};

@private function _execute (action, syncLength, [arguments])

- -

@action {string} Action to execute on this.store.

- -

@syncLength {number} Function length of the sync version.

- -

@arguments {Array} Arguments array to apply to the action

- -

Executes the specified action on all stores for this instance, ensuring a callback supplied -to a synchronous store function is still invoked.

Provider.prototype._execute = function (action, syncLength /* [arguments] */) {
-  var args = Array.prototype.slice.call(arguments, 2),
-      callback = typeof args[args.length - 1] === 'function' && args.pop(),
-      self = this,
-      response;
-
-  function runAction (name, next) {
-    var store = self[name]
-
-    return store[action].length > syncLength
-      ? store[action].apply(store, args.concat(next))
-      : next(null, store[action].apply(store, args));
-  }
-
-  if (callback) {
-    return async.forEach(self._stores, runAction, function (err) {
-      return err ? callback(err) : callback();
-    });
-  }
-
-  this._stores.forEach(function (name) {
-    var store = self[name];
-    response = store[action].apply(store, args);
-  });
-
-  return response;
-}

@argv {boolean}

- -

Gets or sets a property representing overrides which supercede all -other values for this instance.

Provider.prototype.__defineSetter__('overrides', function (val) { updateSystem.call(this, 'overrides', val) });
-Provider.prototype.__defineGetter__('overrides', function () { return this._argv });

@argv {boolean}

- -

Gets or sets a property indicating if we should wrap calls to .get -by checking yargs.argv. Can be a boolean or the pass-thru -options for yargs.

Provider.prototype.__defineSetter__('argv', function (val) { updateSystem.call(this, 'argv', val) });
-Provider.prototype.__defineGetter__('argv', function () { return this._argv });

@env {boolean}

- -

Gets or sets a property indicating if we should wrap calls to .get -by checking process.env. Can be a boolean or an Array of -environment variables to extract.

Provider.prototype.__defineSetter__('env', function (val) { updateSystem.call(this, 'env', val) });
-Provider.prototype.__defineGetter__('env', function () { return this._env });

Throw the err if a callback is not supplied

function onError(err, callback) {
-  if (callback) {
-    return callback(err);
-  }
-
-  throw err;
-}

Helper function for working with the -default system store for providers.

function updateSystem(prop, value) {
-  var system = this['system'];
-
-  if (system[prop] === value) {
-    return;
-  }
-
-  value = value || false;
-  this['_' + prop] = value;
-  system[prop] = value;
-  system.loadSync();
-}
-
-
diff --git a/docs/nconf/stores.html b/docs/nconf/stores.html deleted file mode 100644 index d799966..0000000 --- a/docs/nconf/stores.html +++ /dev/null @@ -1,19 +0,0 @@ - stores.js

stores.js

/*
- * stores.js: Top-level include for all nconf stores
- *
- * (C) 2011, Charlie Robbins
- *
- */
- 
-var fs = require('fs'),
-    common = require('./common'),
-    stores = exports;

Setup all stores as lazy-loaded getters.

fs.readdirSync(__dirname + '/stores').forEach(function (file) {
-  var store = file.replace('.js', ''),
-      name  = common.capitalize(store);
-      
-  stores.__defineGetter__(name, function () {
-    return require('./stores/' + store)[name];
-  });
-});
-
-
\ No newline at end of file diff --git a/docs/nconf/stores/file.html b/docs/nconf/stores/file.html deleted file mode 100644 index 7a00765..0000000 --- a/docs/nconf/stores/file.html +++ /dev/null @@ -1,170 +0,0 @@ - file.js

file.js

/*
- * file.js: Simple file storage engine for nconf files
- *
- * (C) 2011, Charlie Robbins
- *
- */
-
-var fs = require('fs'),
-    path = require('path'),
-    util = require('util'),
-    formats = require('../formats'),
-    Memory = require('./memory').Memory;
- 

function File (options)

- -

@options {Object} Options for this instance

- -

Constructor function for the File nconf store, a simple abstraction -around the Memory store that can persist configuration to disk.

var File = exports.File = function (options) {
-  if (!options || !options.file) {
-    throw new Error ('Missing required option `files`');
-  }
-
-  Memory.call(this, options);
-
-  this.type   = 'file';
-  this.file   = options.file;
-  this.dir    = options.dir    || process.cwd();
-  this.format = options.format || formats.json;
-};

Inherit from the Memory store

util.inherits(File, Memory);

function save (value, callback)

- -

@value {Object} Ignored Left here for consistency

- -

@callback {function} Continuation to respond to when complete.

- -

Saves the current configuration object to disk at this.file -using the format specified by this.format.

File.prototype.save = function (value, callback) {
-  if (!callback) {
-    callback = value;
-    value = null;
-  }
-  
-  fs.writeFile(this.file, this.format.stringify(this.store), function (err) {
-    return err ? callback(err) : callback();
-  });
-};

function saveSync (value, callback)

- -

@value {Object} Ignored Left here for consistency

- -

@callback {function} Optional Continuation to respond to when complete.

- -

Saves the current configuration object to disk at this.file -using the format specified by this.format synchronously.

File.prototype.saveSync = function (value) {
-  try {
-    fs.writeFileSync(this.file, this.format.stringify(this.store));
-  }
-  catch (ex) {
-    throw(ex);
-  }
-};

function load (callback)

- -

@callback {function} Continuation to respond to when complete.

- -

Responds with an Object representing all keys associated in this instance.

File.prototype.load = function (callback) {
-  var self = this;
-
-  path.exists(self.file, function (exists) {
-    if (!exists) {

If the path we are attempting to load doesn't exist, create it

      self.save({}, function (err) {
-        self.store = {};
-        return callback(err, self.store);
-      });
-    }
-    else {

Else, the path exists, read it from disk

      fs.readFile(self.file, function (err, data) {
-        if (err) {
-          return callback(err);
-        }
-        
-        try {
-          self.store = self.format.parse(data.toString());
-        }
-        catch (ex) {
-          return callback(new Error("Error parsing your JSON configuration file."));
-        }
-        
-        callback(null, self.store);
-      });
-    }
-  });
-};

function load (callback)

- -

@callback {function} Optional Continuation to respond to when complete.

- -

Attempts to load the data stored in this.file synchronously and responds appropriately.

File.prototype.loadSync = function () {
-  var data, self = this;
-
-  if (!path.existsSync(self.file)) {

If the path we are attempting to load doesn't exist, create it

    self.saveSync({});
-    self.store = {};
-    data = {};
-  }
-  else {

Else, the path exists, read it from disk

    try {
-      data = this.format.parse(fs.readFileSync(this.file, 'utf8'));
-      this.store = data;
-    }
-    catch (ex) {
-      throw new Error("Error parsing your JSON configuration file.")
-    }
-  }
-
-  return data;
-};

function search (base)

- -

@base {string} Base directory (or file) to begin searching for the target file.

- -

Attempts to find this.file by iteratively searching up the -directory structure

File.prototype.search = function (base) {
-  var looking = true,
-      fullpath,
-      previous,
-      stats;
-
-  base = base || process.cwd();
-
-  if (this.file[0] === '/') {

If filename for this instance is a fully qualified path -(i.e. it starts with a '/') then check if it exists

    try {
-      stats = fs.statSync(fs.realpathSync(this.file));
-      if (stats.isFile()) {
-        fullpath = this.file;
-        looking = false;
-      }
-    }
-    catch (ex) {

Ignore errors

    }
-  }
-
-  if (looking && base) {

Attempt to stat the realpath located at base -if the directory does not exist then return false.

    try {
-      var stat = fs.statSync(fs.realpathSync(base));
-      looking = stat.isDirectory();
-    }
-    catch (ex) {
-      return false;
-    }
-  }
-  
-  while (looking) {

Iteratively look up the directory structure from base

    try {
-      stats = fs.statSync(fs.realpathSync(fullpath = path.join(base, this.file)));
-      looking = stats.isDirectory();
-    }
-    catch (ex) {
-      previous = base;
-      base = path.dirname(base);
-
-      if (previous === base) {

If we've reached the top of the directory structure then simply use -the default file path.

        try {
-          stats = fs.statSync(fs.realpathSync(fullpath = path.join(this.dir, this.file)));
-          if (stats.isDirectory()) {
-            fullpath = undefined;
-          }
-        }
-        catch (ex) {

Ignore errors

        }
-        
-        looking = false;
-      }
-    }
-  }

Set the file for this instance to the fullpath -that we have found during the search. In the event that -the search was unsuccessful use the original value for this.file.

  this.file = fullpath || this.file;
-  
-  return fullpath;
-};
-
-
\ No newline at end of file diff --git a/docs/nconf/stores/memory.html b/docs/nconf/stores/memory.html deleted file mode 100644 index 8867394..0000000 --- a/docs/nconf/stores/memory.html +++ /dev/null @@ -1,143 +0,0 @@ - memory.js

memory.js

/*
- * memory.js: Simple memory storage engine for nconf configuration(s)
- *
- * (C) 2011, Charlie Robbins
- *
- */
-
-var common = require('../common');

function Memory (options)

- -

@options {Object} Options for this instance

- -

Constructor function for the Memory nconf store which maintains -a nested json structure based on key delimiters :.

- -

e.g. my:nested:key ==> { my: { nested: { key: } } }

var Memory = exports.Memory = function (options) {
-  options       = options || {};
-  this.type     = 'memory';
-  this.store    = {};
-  this.mtimes   = {};
-  this.readOnly = false;
-  this.loadFrom = options.loadFrom || null;
-  
-  if (this.loadFrom) {
-    this.store = common.loadFilesSync(this.loadFrom);
-  }
-};

function get (key)

- -

@key {string} Key to retrieve for this instance.

- -

Retrieves the value for the specified key (if any).

Memory.prototype.get = function (key) {
-  var target = this.store, 
-      path   = common.path(key);

Scope into the object to get the appropriate nested context

  while (path.length > 0) {
-    key = path.shift();
-    if (!(target && key in target)) {
-      return;
-    }
-    
-    target = target[key];
-    if (path.length === 0) {
-      return target;
-    }
-  }
-};

function set (key, value)

- -

@key {string} Key to set in this instance

- -

@value {literal|Object} Value for the specified key

- -

Sets the value for the specified key in this instance.

Memory.prototype.set = function (key, value) {
-  if (this.readOnly) {
-    return false;
-  }
-  
-  var target = this.store, 
-      path   = common.path(key);
-  

Update the mtime (modified time) of the key

  this.mtimes[key] = Date.now();
-  

Scope into the object to get the appropriate nested context

  while (path.length > 1) {
-    key = path.shift();
-    if (!target[key] || typeof target[key] !== 'object') {
-      target[key] = {};
-    }
-    
-    target = target[key];
-  }
-  

Set the specified value in the nested JSON structure

  key = path.shift();
-  target[key] = value;
-  return true;
-};

function clear (key)

- -

@key {string} Key to remove from this instance

- -

Removes the value for the specified key from this instance.

Memory.prototype.clear = function (key) {
-  if (this.readOnly) {
-    return false;
-  }
-  
-  var target = this.store, 
-      path   = common.path(key);
-  

Remove the key from the set of mtimes (modified times)

  delete this.mtimes[key];
-  

Scope into the object to get the appropriate nested context

  while (path.length > 1) {
-    key = path.shift();
-    if (!target[key]) {
-      return;
-    }
-    
-    target = target[key];
-  }
-  

Delete the key from the nested JSON structure

  key = path.shift();
-  delete target[key];
-  return true;
-};

function merge (key, value)

- -

@key {string} Key to merge the value into

- -

@value {literal|Object} Value to merge into the key

- -

Merges the properties in value into the existing object value -at key. If the existing value key is not an Object, it will be -completely overwritten.

Memory.prototype.merge = function (key, value) {
-  if (this.readOnly) {
-    return false;
-  }
-  

If the key is not an Object or is an Array, -then simply set it. Merging is for Objects.

  if (typeof value !== 'object' || Array.isArray(value)) {
-    return this.set(key, value);
-  }
-  
-  var self    = this,
-      target  = this.store, 
-      path    = common.path(key),
-      fullKey = key;
-  

Update the mtime (modified time) of the key

  this.mtimes[key] = Date.now();
-  

Scope into the object to get the appropriate nested context

  while (path.length > 1) {
-    key = path.shift();
-    if (!target[key]) {
-      target[key] = {};
-    }
-    
-    target = target[key];
-  }

Set the specified value in the nested JSON structure

  key = path.shift();
-  

If the current value at the key target is not an Object, -or is an Array then simply override it because the new value -is an Object.

  if (typeof target[key] !== 'object' || Array.isArray(target[key])) {
-    target[key] = value;
-    return true;
-  }
-  
-  return Object.keys(value).every(function (nested) {
-    return self.merge(fullKey + ':' + nested, value[nested]);
-  });
-};

function reset (callback)

- -

Clears all keys associated with this instance.

Memory.prototype.reset = function () {
-  if (this.readOnly) {
-    return false;
-  }
-  
-  this.mtimes = {};
-  this.store  = {};
-  return true;
-};
-
-
\ No newline at end of file diff --git a/docs/nconf/stores/system.html b/docs/nconf/stores/system.html deleted file mode 100644 index 6a10015..0000000 --- a/docs/nconf/stores/system.html +++ /dev/null @@ -1,98 +0,0 @@ - system.js

system.js

/*
- * system.js: Simple memory-based store for process environment variables and
- *            command-line arguments.
- *
- * (C) 2011, Charlie Robbins
- *
- */
-
-var util = require('util'),
-    Memory = require('./memory').Memory;
- 

function System (options)

- -

@options {Object} Options for this instance.

- -

Constructor function for the System nconf store, a simple abstraction -around the Memory store that can read process environment variables -and command-line arguments.

var System = exports.System = function (options) {
-  options = options || {};
-  Memory.call(this, options);
-
-  this.type      = 'system';
-  this.overrides = options.overrides || null;
-  this.env       = options.env       || false;
-  this.argv      = options.argv      || false;
-};

Inherit from the Memory store

util.inherits(System, Memory);

function loadSync ()

- -

Loads the data passed in from process.env into this instance.

System.prototype.loadSync = function () {
-  if (this.env) {
-    this.loadEnv();
-  }
-
-  if (this.argv) {
-    this.loadArgv();
-  }
-
-  if (this.overrides) {
-    this.loadOverrides();
-  }
-
-  return this.store;
-};

function loadOverrides ()

- -

Loads any overrides set on this instance into -the underlying managed Memory store.

System.prototype.loadOverrides = function () {
-  if (!this.overrides) {
-    return;
-  }
-
-  var self = this,
-      keys = Object.keys(this.overrides);
-
-  keys.forEach(function (key) {
-    self.set(key, self.overrides[key]);
-  });
-
-  return this.store;
-};

function loadArgv ()

- -

Loads the data passed in from the command-line arguments -into this instance.

System.prototype.loadArgv = function () {
-  var self = this,
-      argv;
-
-  if (typeof this.argv === 'object') {
-    argv = require('yargs').options(this.argv).argv;
-  }
-  else if (this.argv) {
-    argv = require('yargs').argv;
-  }
-
-  if (!argv) {
-    return;
-  }
-
-  Object.keys(argv).forEach(function (key) {
-    self.set(key, argv[key]);
-  });
-
-  return this.store;
-};

function loadEnv ()

- -

Loads the data passed in from process.env into this instance.

System.prototype.loadEnv = function () {
-  var self = this;
-
-  if (!this.env) {
-    return;
-  }
-
-  Object.keys(process.env).filter(function (key) {
-    return !self.env.length || self.env.indexOf(key) !== -1;
-  }).forEach(function (key) {
-    self.set(key, process.env[key]);
-  });
-
-  return this.store;
-};
-
-