lorenwest/node-config — pull request #164 by markstos (2014-11-14 01:56:01+00:00)
Title: Add support for defered configuration values.

As seen in the included tests, a new feature is added to allow you declare a
configuration value as a special kind of function in .js files.

This is useful to create default configuration values based on other
configuration values when other further configuration files may override the
values being referenced.

You can think of this as allowing you declare "templates" which contain
variables referencing other config values in the configuration file, which are
then "rendered" with the correct values once all the config files have been
loaded in merged.

One test shows that the addition is backwards compatible with config files
that have been using functions as values. Only functions which are instance of
the newly provided DeferredConfig class are handled specially.

For example use see:

test/3-deferred-configs.js
test/config/default-defer.js
test/config/local-defer.js

---

I looked for other names to avoid the name 'defer' and 'deferred', since 'deferred' is used
by some promise library. Finding nothing that better conveyed what this feature does, I settled
on the name 'deferConfig', which will not conflict with promise libraries name of 'defer' or 'deferred'.
However, people can alias the name to simply 'defer()' in their config files upon import if they
prefer the shorter name.

---

Note also the use of module un-loading / reloading in the new test file.

I found adding tests to the "2" test file to be challenging because it references
so many configuration files and values with a complex cascading relationship.

By using the unload/reload pattern, I was able to a small isolated test that is
easy to review and maintain without intefering with the existing battery of
tests.