[doc] Updated docco docs

This commit is contained in:
indexzero 2011-09-18 21:39:13 -04:00
parent f867e749b9
commit c4c8d7b76f
9 changed files with 465 additions and 469 deletions

View file

@ -1,4 +1,4 @@
<!DOCTYPE html> <html> <head> <title>nconf.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="nconf/common.html"> nconf/common.html </a> <a class="source" href="nconf/formats.html"> nconf/formats.html </a> <a class="source" href="nconf/provider.html"> nconf/provider.html </a> <a class="source" href="nconf/stores/file.html"> nconf/stores/file.html </a> <a class="source" href="nconf/stores/memory.html"> nconf/stores/memory.html </a> <a class="source" href="nconf/stores.html"> nconf/stores.html </a> <a class="source" href="nconf.html"> nconf.html </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> nconf.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
<!DOCTYPE html> <html> <head> <title>nconf.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="nconf/common.html"> nconf/common.html </a> <a class="source" href="nconf/formats.html"> nconf/formats.html </a> <a class="source" href="nconf/provider.html"> nconf/provider.html </a> <a class="source" href="nconf/stores/file.html"> nconf/stores/file.html </a> <a class="source" href="nconf/stores/memory.html"> nconf/stores/memory.html </a> <a class="source" href="nconf/stores/system.html"> nconf/stores/system.html </a> <a class="source" href="nconf/stores.html"> nconf/stores.html </a> <a class="source" href="nconf.html"> nconf.html </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> nconf.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
<span class="cm"> * nconf.js: Top-level include for the nconf module</span>
<span class="cm"> *</span>
<span class="cm"> * (C) 2011, Charlie Robbins</span>
@ -9,17 +9,10 @@
<span class="nx">async</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;async&#39;</span><span class="p">),</span>
<span class="nx">common</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./nconf/common&#39;</span><span class="p">),</span>
<span class="nx">Provider</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./nconf/provider&#39;</span><span class="p">).</span><span class="nx">Provider</span><span class="p">,</span>
<span class="nx">nconf</span> <span class="o">=</span> <span class="nx">module</span><span class="p">.</span><span class="nx">exports</span> <span class="o">=</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">create</span><span class="p">(</span><span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>Use the memory engine by default.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">nconf</span><span class="p">.</span><span class="nx">use</span><span class="p">(</span><span class="s1">&#39;memory&#39;</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Expose the version from the package.json using <code>pkginfo</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">require</span><span class="p">(</span><span class="s1">&#39;pkginfo&#39;</span><span class="p">)(</span><span class="nx">module</span><span class="p">,</span> <span class="s1">&#39;version&#39;</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <h3>function path (key)</h3>
<h4>@key {string} The ':' delimited key to split</h4>
<p>Returns a fully-qualified path to a nested nconf key. </p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">nconf</span><span class="p">.</span><span class="nx">path</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">key</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s1">&#39;:&#39;</span><span class="p">);</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <h3>function key (arguments)</h3>
<p>Returns a <code>:</code> joined string from the <code>arguments</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">nconf</span><span class="p">.</span><span class="nx">key</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="k">return</span> <span class="nb">Array</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">slice</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">arguments</span><span class="p">).</span><span class="nx">join</span><span class="p">(</span><span class="s1">&#39;:&#39;</span><span class="p">);</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Expose the various components included with nconf</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">nconf</span><span class="p">.</span><span class="nx">loadFiles</span> <span class="o">=</span> <span class="nx">common</span><span class="p">.</span><span class="nx">loadFiles</span><span class="p">;</span>
<span class="nx">nconf</span> <span class="o">=</span> <span class="nx">module</span><span class="p">.</span><span class="nx">exports</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Provider</span><span class="p">();</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>Expose the version from the package.json using <code>pkginfo</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">require</span><span class="p">(</span><span class="s1">&#39;pkginfo&#39;</span><span class="p">)(</span><span class="nx">module</span><span class="p">,</span> <span class="s1">&#39;version&#39;</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Expose the various components included with nconf</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">nconf</span><span class="p">.</span><span class="nx">key</span> <span class="o">=</span> <span class="nx">common</span><span class="p">.</span><span class="nx">key</span><span class="p">;</span>
<span class="nx">nconf</span><span class="p">.</span><span class="nx">path</span> <span class="o">=</span> <span class="nx">common</span><span class="p">.</span><span class="nx">path</span><span class="p">;</span>
<span class="nx">nconf</span><span class="p">.</span><span class="nx">loadFiles</span> <span class="o">=</span> <span class="nx">common</span><span class="p">.</span><span class="nx">loadFiles</span><span class="p">;</span>
<span class="nx">nconf</span><span class="p">.</span><span class="nx">loadFilesSync</span> <span class="o">=</span> <span class="nx">common</span><span class="p">.</span><span class="nx">loadFilesSync</span><span class="p">;</span>
<span class="nx">nconf</span><span class="p">.</span><span class="nx">formats</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./nconf/formats&#39;</span><span class="p">);</span>
<span class="nx">nconf</span><span class="p">.</span><span class="nx">stores</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./nconf/stores&#39;</span><span class="p">);</span>
<span class="nx">nconf</span><span class="p">.</span><span class="nx">Provider</span> <span class="o">=</span> <span class="nx">Provider</span><span class="p">;</span>

View file

@ -1,4 +1,4 @@
<!DOCTYPE html> <html> <head> <title>common.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="../docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="..//nconf/common.html"> nconf/common.html </a> <a class="source" href="..//nconf/formats.html"> nconf/formats.html </a> <a class="source" href="..//nconf/provider.html"> nconf/provider.html </a> <a class="source" href="..//nconf/stores/file.html"> nconf/stores/file.html </a> <a class="source" href="..//nconf/stores/memory.html"> nconf/stores/memory.html </a> <a class="source" href="..//nconf/stores.html"> nconf/stores.html </a> <a class="source" href="..//nconf.html"> nconf.html </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> common.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
<!DOCTYPE html> <html> <head> <title>common.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="../docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="..//nconf/common.html"> nconf/common.html </a> <a class="source" href="..//nconf/formats.html"> nconf/formats.html </a> <a class="source" href="..//nconf/provider.html"> nconf/provider.html </a> <a class="source" href="..//nconf/stores/file.html"> nconf/stores/file.html </a> <a class="source" href="..//nconf/stores/memory.html"> nconf/stores/memory.html </a> <a class="source" href="..//nconf/stores/system.html"> nconf/stores/system.html </a> <a class="source" href="..//nconf/stores.html"> nconf/stores.html </a> <a class="source" href="..//nconf.html"> nconf.html </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> common.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
<span class="cm"> * utils.js: Utility functions for the nconf module.</span>
<span class="cm"> *</span>
<span class="cm"> * (C) 2011, Charlie Robbins</span>
@ -8,9 +8,19 @@
<span class="kd">var</span> <span class="nx">fs</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;fs&#39;</span><span class="p">),</span>
<span class="nx">async</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;async&#39;</span><span class="p">),</span>
<span class="nx">formats</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./formats&#39;</span><span class="p">),</span>
<span class="nx">stores</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./stores&#39;</span><span class="p">);</span>
<span class="nx">Memory</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./stores/Memory&#39;</span><span class="p">).</span><span class="nx">Memory</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">common</span> <span class="o">=</span> <span class="nx">exports</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <h3>function loadFiles (files)</h3>
<span class="kd">var</span> <span class="nx">common</span> <span class="o">=</span> <span class="nx">exports</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <h3>function path (key)</h3>
<h4>@key {string} The ':' delimited key to split</h4>
<p>Returns a fully-qualified path to a nested nconf key. </p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">common</span><span class="p">.</span><span class="nx">path</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">key</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s1">&#39;:&#39;</span><span class="p">);</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <h3>function key (arguments)</h3>
<p>Returns a <code>:</code> joined string from the <code>arguments</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">common</span><span class="p">.</span><span class="nx">key</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="k">return</span> <span class="nb">Array</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">slice</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">arguments</span><span class="p">).</span><span class="nx">join</span><span class="p">(</span><span class="s1">&#39;:&#39;</span><span class="p">);</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <h3>function loadFiles (files, callback)</h3>
<h4>@files {Object|Array} List of files (or settings object) to load.</h4>
@ -21,28 +31,55 @@
<span class="k">return</span> <span class="nx">callback</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="p">{});</span>
<span class="p">}</span>
<span class="kd">var</span> <span class="nx">options</span> <span class="o">=</span> <span class="nb">Array</span><span class="p">.</span><span class="nx">isArray</span><span class="p">(</span><span class="nx">files</span><span class="p">)</span> <span class="o">?</span> <span class="p">{</span> <span class="nx">files</span><span class="o">:</span> <span class="nx">files</span> <span class="p">}</span> <span class="o">:</span> <span class="nx">files</span><span class="p">,</span>
<span class="nx">store</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">stores</span><span class="p">.</span><span class="nx">Memory</span><span class="p">();</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Set the default JSON format if not already
<span class="kd">var</span> <span class="nx">options</span> <span class="o">=</span> <span class="nb">Array</span><span class="p">.</span><span class="nx">isArray</span><span class="p">(</span><span class="nx">files</span><span class="p">)</span> <span class="o">?</span> <span class="p">{</span> <span class="nx">files</span><span class="o">:</span> <span class="nx">files</span> <span class="p">}</span> <span class="o">:</span> <span class="nx">files</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Set the default JSON format if not already
specified</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">options</span><span class="p">.</span><span class="nx">format</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">format</span> <span class="o">||</span> <span class="nx">formats</span><span class="p">.</span><span class="nx">json</span><span class="p">;</span>
<span class="kd">function</span> <span class="nx">loadFile</span> <span class="p">(</span><span class="nx">file</span><span class="p">,</span> <span class="nx">next</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">function</span> <span class="nx">parseFile</span> <span class="p">(</span><span class="nx">file</span><span class="p">,</span> <span class="nx">next</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">fs</span><span class="p">.</span><span class="nx">readFile</span><span class="p">(</span><span class="nx">file</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">data</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">next</span><span class="p">(</span><span class="nx">err</span><span class="p">);</span>
<span class="p">}</span>
<span class="nx">data</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">format</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="nx">data</span><span class="p">.</span><span class="nx">toString</span><span class="p">());</span>
<span class="nb">Object</span><span class="p">.</span><span class="nx">keys</span><span class="p">(</span><span class="nx">data</span><span class="p">).</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">store</span><span class="p">.</span><span class="nx">merge</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">data</span><span class="p">[</span><span class="nx">key</span><span class="p">]);</span>
<span class="p">});</span>
<span class="nx">next</span><span class="p">();</span>
<span class="k">return</span> <span class="o">!</span><span class="nx">err</span>
<span class="o">?</span> <span class="nx">next</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="nx">options</span><span class="p">.</span><span class="nx">format</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="nx">data</span><span class="p">.</span><span class="nx">toString</span><span class="p">()))</span>
<span class="o">:</span> <span class="nx">next</span><span class="p">(</span><span class="nx">err</span><span class="p">);</span>
<span class="p">});</span>
<span class="p">}</span>
<span class="nx">async</span><span class="p">.</span><span class="nx">forEach</span><span class="p">(</span><span class="nx">files</span><span class="p">,</span> <span class="nx">loadFile</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">err</span> <span class="o">?</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="o">:</span> <span class="nx">callback</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="nx">store</span><span class="p">.</span><span class="nx">store</span><span class="p">);</span>
<span class="nx">async</span><span class="p">.</span><span class="nx">map</span><span class="p">(</span><span class="nx">files</span><span class="p">,</span> <span class="nx">parseFile</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">objs</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">err</span> <span class="o">?</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="o">:</span> <span class="nx">callback</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="nx">common</span><span class="p">.</span><span class="nx">merge</span><span class="p">(</span><span class="nx">objs</span><span class="p">));</span>
<span class="p">});</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <h3>function loadFilesSync (files)</h3>
<h4>@files {Object|Array} List of files (or settings object) to load.</h4>
<p>Loads all the data in the specified <code>files</code> synchronously.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">common</span><span class="p">.</span><span class="nx">loadFilesSync</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">files</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">files</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span><span class="p">;</span>
<span class="p">}</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Set the default JSON format if not already
specified</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">options</span> <span class="o">=</span> <span class="nb">Array</span><span class="p">.</span><span class="nx">isArray</span><span class="p">(</span><span class="nx">files</span><span class="p">)</span> <span class="o">?</span> <span class="p">{</span> <span class="nx">files</span><span class="o">:</span> <span class="nx">files</span> <span class="p">}</span> <span class="o">:</span> <span class="nx">files</span><span class="p">;</span>
<span class="nx">options</span><span class="p">.</span><span class="nx">format</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">format</span> <span class="o">||</span> <span class="nx">formats</span><span class="p">.</span><span class="nx">json</span><span class="p">;</span>
<span class="k">return</span> <span class="nx">common</span><span class="p">.</span><span class="nx">merge</span><span class="p">(</span><span class="nx">files</span><span class="p">.</span><span class="nx">map</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">file</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">options</span><span class="p">.</span><span class="nx">format</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="nx">fs</span><span class="p">.</span><span class="nx">readFileSync</span><span class="p">(</span><span class="nx">file</span><span class="p">,</span> <span class="s1">&#39;utf8&#39;</span><span class="p">));</span>
<span class="p">}));</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <h3>function merge (objs)</h3>
<h4>@objs {Array} Array of object literals to merge</h4>
<p>Merges the specified <code>objs</code> using a temporary instance
of <code>stores.Memory</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">common</span><span class="p">.</span><span class="nx">merge</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">objs</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">store</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Memory</span><span class="p">();</span>
<span class="nx">objs</span><span class="p">.</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="p">{</span>
<span class="nb">Object</span><span class="p">.</span><span class="nx">keys</span><span class="p">(</span><span class="nx">obj</span><span class="p">).</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">store</span><span class="p">.</span><span class="nx">merge</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">obj</span><span class="p">[</span><span class="nx">key</span><span class="p">]);</span>
<span class="p">});</span>
<span class="p">});</span>
<span class="k">return</span> <span class="nx">store</span><span class="p">.</span><span class="nx">store</span><span class="p">;</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <h3>function capitalize (str)</h3>
<h4>@str {string} String to capitalize</h4>
<p>Capitalizes the specified <code>str</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">common</span><span class="p">.</span><span class="nx">capitalize</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">str</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">str</span> <span class="o">&amp;&amp;</span> <span class="nx">str</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">toUpperCase</span><span class="p">()</span> <span class="o">+</span> <span class="nx">str</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
<span class="p">};</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>

View file

@ -1,4 +1,4 @@
<!DOCTYPE html> <html> <head> <title>formats.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="../docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="..//nconf/common.html"> nconf/common.html </a> <a class="source" href="..//nconf/formats.html"> nconf/formats.html </a> <a class="source" href="..//nconf/provider.html"> nconf/provider.html </a> <a class="source" href="..//nconf/stores/file.html"> nconf/stores/file.html </a> <a class="source" href="..//nconf/stores/memory.html"> nconf/stores/memory.html </a> <a class="source" href="..//nconf/stores.html"> nconf/stores.html </a> <a class="source" href="..//nconf.html"> nconf.html </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> formats.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
<!DOCTYPE html> <html> <head> <title>formats.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="../docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="..//nconf/common.html"> nconf/common.html </a> <a class="source" href="..//nconf/formats.html"> nconf/formats.html </a> <a class="source" href="..//nconf/provider.html"> nconf/provider.html </a> <a class="source" href="..//nconf/stores/file.html"> nconf/stores/file.html </a> <a class="source" href="..//nconf/stores/memory.html"> nconf/stores/memory.html </a> <a class="source" href="..//nconf/stores/system.html"> nconf/stores/system.html </a> <a class="source" href="..//nconf/stores.html"> nconf/stores.html </a> <a class="source" href="..//nconf.html"> nconf.html </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> formats.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
<span class="cm"> * formats.js: Default formats supported by nconf</span>
<span class="cm"> *</span>
<span class="cm"> * (C) 2011, Charlie Robbins</span>

View file

@ -1,4 +1,4 @@
<!DOCTYPE html> <html> <head> <title>provider.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="../docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="..//nconf/common.html"> nconf/common.html </a> <a class="source" href="..//nconf/formats.html"> nconf/formats.html </a> <a class="source" href="..//nconf/provider.html"> nconf/provider.html </a> <a class="source" href="..//nconf/stores/file.html"> nconf/stores/file.html </a> <a class="source" href="..//nconf/stores/memory.html"> nconf/stores/memory.html </a> <a class="source" href="..//nconf/stores.html"> nconf/stores.html </a> <a class="source" href="..//nconf.html"> nconf.html </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> provider.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
<!DOCTYPE html> <html> <head> <title>provider.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="../docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="..//nconf/common.html"> nconf/common.html </a> <a class="source" href="..//nconf/formats.html"> nconf/formats.html </a> <a class="source" href="..//nconf/provider.html"> nconf/provider.html </a> <a class="source" href="..//nconf/stores/file.html"> nconf/stores/file.html </a> <a class="source" href="..//nconf/stores/memory.html"> nconf/stores/memory.html </a> <a class="source" href="..//nconf/stores/system.html"> nconf/stores/system.html </a> <a class="source" href="..//nconf/stores.html"> nconf/stores.html </a> <a class="source" href="..//nconf.html"> nconf.html </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> provider.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
<span class="cm"> * provider.js: Abstraction providing an interface into pluggable configuration storage.</span>
<span class="cm"> *</span>
<span class="cm"> * (C) 2011, Charlie Robbins</span>
@ -6,7 +6,6 @@
<span class="cm"> */</span>
<span class="kd">var</span> <span class="nx">async</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;async&#39;</span><span class="p">),</span>
<span class="nx">optimist</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;optimist&#39;</span><span class="p">),</span>
<span class="nx">common</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./common&#39;</span><span class="p">),</span>
<span class="nx">stores</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./stores&#39;</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <h3>function Provider (options)</h3>
@ -14,51 +13,161 @@
<p>Constructor function for the Provider object responsible
for exposing the pluggable storage features of <code>nconf</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">Provider</span> <span class="o">=</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">Provider</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">options</span> <span class="o">=</span> <span class="nx">options</span> <span class="o">||</span> <span class="p">{};</span>
<span class="k">this</span><span class="p">.</span><span class="nx">overrides</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">overrides</span> <span class="o">||</span> <span class="kc">null</span>
<span class="k">this</span><span class="p">.</span><span class="nx">useArgv</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">useArgv</span> <span class="o">||</span> <span class="kc">false</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span>
</pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Setup default options for working with <code>stores</code>,
<code>overrides</code>, <code>process.env</code> and <code>process.argv</code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">options</span> <span class="o">=</span> <span class="nx">options</span> <span class="o">||</span> <span class="p">{};</span>
<span class="k">this</span><span class="p">.</span><span class="nx">_overrides</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">overrides</span> <span class="o">||</span> <span class="kc">null</span><span class="p">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">_argv</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">argv</span> <span class="o">||</span> <span class="kc">false</span><span class="p">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">_env</span><span class="err"> </span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">env</span> <span class="o">||</span> <span class="kc">false</span><span class="p">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">_reserved</span> <span class="o">=</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">keys</span><span class="p">(</span><span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">);</span>
<span class="k">this</span><span class="p">.</span><span class="nx">_stores</span> <span class="o">=</span> <span class="p">[];</span>
</pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>Add the default <code>system</code> store for working with
<code>overrides</code>, <code>process.env</code>, <code>process.argv</code> and
a simple in-memory objects.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">add</span><span class="p">(</span><span class="s1">&#39;system&#39;</span><span class="p">,</span> <span class="nx">options</span><span class="p">);</span>
<span class="k">this</span><span class="p">.</span><span class="nx">store</span> <span class="o">=</span> <span class="nx">stores</span><span class="p">.</span><span class="nx">create</span><span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">type</span> <span class="o">||</span> <span class="s1">&#39;memory&#39;</span><span class="p">,</span> <span class="nx">options</span><span class="p">);</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <h3>function use (type, options)</h3>
<span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">type</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">add</span><span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">type</span><span class="p">,</span> <span class="nx">options</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">store</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">add</span><span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">store</span><span class="p">.</span><span class="nx">name</span> <span class="o">||</span> <span class="nx">options</span><span class="p">.</span><span class="nx">store</span><span class="p">.</span><span class="nx">type</span><span class="p">,</span> <span class="nx">options</span><span class="p">.</span><span class="nx">store</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">stores</span><span class="p">)</span> <span class="p">{</span>
<span class="nb">Object</span><span class="p">.</span><span class="nx">keys</span><span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">stores</span><span class="p">).</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">store</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">self</span><span class="p">.</span><span class="nx">add</span><span class="p">(</span><span class="nx">store</span><span class="p">.</span><span class="nx">name</span> <span class="o">||</span> <span class="nx">store</span><span class="p">.</span><span class="nx">type</span><span class="p">,</span> <span class="nx">store</span><span class="p">);</span>
<span class="p">});</span>
<span class="p">}</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <h3>function use (name, options)</h3>
<h4>@type {string} Type of the nconf store to use.</h4>
<h4>@options {Object} Options for the store instance.</h4>
<p>Sets the active <code>this.store</code> to a new instance of the
specified <code>type</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">use</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">type</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span>
<span class="nx">options</span> <span class="o">=</span> <span class="nx">options</span> <span class="o">||</span> <span class="p">{};</span>
<p>Adds (or replaces) a new store with the specified <code>name</code>
and <code>options</code>. If <code>options.type</code> is not set, then <code>name</code>
will be used instead:</p>
<span class="kd">function</span> <span class="nx">sameOptions</span> <span class="p">()</span> <span class="p">{</span>
<p>provider.use('file');
provider.use('file', { type: 'file', filename: '/path/to/userconf' })</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">use</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">name</span> <span class="o">===</span> <span class="s1">&#39;system&#39;</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">_reserved</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="nx">name</span><span class="p">)</span> <span class="o">!==</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s1">&#39;Cannot use reserved name: &#39;</span> <span class="o">+</span> <span class="nx">name</span><span class="p">);</span>
<span class="p">}</span>
<span class="nx">options</span> <span class="o">=</span> <span class="nx">options</span> <span class="o">||</span> <span class="p">{};</span>
<span class="kd">var</span> <span class="nx">type</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">type</span> <span class="o">||</span> <span class="nx">name</span><span class="p">;</span>
<span class="kd">function</span> <span class="nx">sameOptions</span> <span class="p">(</span><span class="nx">store</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">keys</span><span class="p">(</span><span class="nx">options</span><span class="p">).</span><span class="nx">every</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">options</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">===</span> <span class="nx">self</span><span class="p">.</span><span class="nx">store</span><span class="p">[</span><span class="nx">key</span><span class="p">];</span>
<span class="k">return</span> <span class="nx">options</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">===</span> <span class="nx">store</span><span class="p">[</span><span class="nx">key</span><span class="p">];</span>
<span class="p">});</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="k">this</span><span class="p">.</span><span class="nx">store</span> <span class="o">||</span> <span class="nx">type</span><span class="p">.</span><span class="nx">toLowerCase</span><span class="p">()</span> <span class="o">!==</span> <span class="k">this</span><span class="p">.</span><span class="nx">store</span><span class="p">.</span><span class="nx">type</span>
<span class="o">||</span> <span class="o">!</span><span class="nx">sameOptions</span><span class="p">())</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">store</span> <span class="o">=</span> <span class="nx">stores</span><span class="p">.</span><span class="nx">create</span><span class="p">(</span><span class="nx">type</span><span class="p">,</span> <span class="nx">options</span><span class="p">);</span>
<span class="kd">var</span> <span class="nx">store</span> <span class="o">=</span> <span class="k">this</span><span class="p">[</span><span class="nx">name</span><span class="p">],</span>
<span class="nx">update</span> <span class="o">=</span> <span class="nx">store</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="nx">sameOptions</span><span class="p">(</span><span class="nx">store</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">store</span> <span class="o">||</span> <span class="nx">update</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">update</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">remove</span><span class="p">(</span><span class="nx">name</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">this</span><span class="p">.</span><span class="nx">add</span><span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">options</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="k">this</span><span class="p">;</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <h3>function get (key, callback)</h3>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <h3>function add (name, options)</h3>
<h4>@name {string} Name of the store to add to this instance</h4>
<h4>@options {Object} Options for the store to create</h4>
<p>Adds a new store with the specified <code>name</code> and <code>options</code>. If <code>options.type</code>
is not set, then <code>name</code> will be used instead:</p>
<p>provider.add('memory');
provider.add('userconf', { type: 'file', filename: '/path/to/userconf' })</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">add</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">_reserved</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="nx">name</span><span class="p">)</span> <span class="o">!==</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s1">&#39;Cannot use reserved name: &#39;</span> <span class="o">+</span> <span class="nx">name</span><span class="p">);</span>
<span class="p">}</span>
<span class="nx">options</span> <span class="o">=</span> <span class="nx">options</span> <span class="o">||</span> <span class="p">{};</span>
<span class="kd">var</span> <span class="nx">type</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">type</span> <span class="o">||</span> <span class="nx">name</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nb">Object</span><span class="p">.</span><span class="nx">keys</span><span class="p">(</span><span class="nx">stores</span><span class="p">).</span><span class="nx">indexOf</span><span class="p">(</span><span class="nx">common</span><span class="p">.</span><span class="nx">capitalize</span><span class="p">(</span><span class="nx">type</span><span class="p">))</span> <span class="o">===</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s1">&#39;Cannot add store with unknown type: &#39;</span> <span class="o">+</span> <span class="nx">type</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">this</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">create</span><span class="p">(</span><span class="nx">type</span><span class="p">,</span> <span class="nx">options</span><span class="p">);</span>
<span class="k">this</span><span class="p">.</span><span class="nx">_stores</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">name</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">[</span><span class="nx">name</span><span class="p">].</span><span class="nx">loadSync</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">[</span><span class="nx">name</span><span class="p">].</span><span class="nx">loadSync</span><span class="p">();</span>
<span class="p">}</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <h3>function remove (name)</h3>
<h4>@name {string} Name of the store to remove from this instance</h4>
<p>Removes a store with the specified <code>name</code> from this instance. Users
are allowed to pass in a type argument (e.g. <code>memory</code>) as name if
this was used in the call to <code>.add()</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">remove</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">name</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">_reserved</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="nx">name</span><span class="p">)</span> <span class="o">!==</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s1">&#39;Cannot use reserved name: &#39;</span> <span class="o">+</span> <span class="nx">name</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="k">this</span><span class="p">[</span><span class="nx">name</span><span class="p">])</span> <span class="p">{</span>
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s1">&#39;Cannot remove store that does not exist: &#39;</span> <span class="o">+</span> <span class="nx">name</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">delete</span> <span class="k">this</span><span class="p">[</span><span class="nx">name</span><span class="p">];</span>
<span class="k">this</span><span class="p">.</span><span class="nx">_stores</span><span class="p">.</span><span class="nx">splice</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">_stores</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="nx">name</span><span class="p">),</span> <span class="mi">1</span><span class="p">);</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <h3>function create (type, options)</h3>
<h4>@type {string} Type of the nconf store to use.</h4>
<h4>@options {Object} Options for the store instance.</h4>
<p>Creates a store of the specified <code>type</code> using the
specified <code>options</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">create</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">type</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">new</span> <span class="nx">stores</span><span class="p">[</span><span class="nx">common</span><span class="p">.</span><span class="nx">capitalize</span><span class="p">(</span><span class="nx">type</span><span class="p">.</span><span class="nx">toLowerCase</span><span class="p">())](</span><span class="nx">options</span><span class="p">);</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <h3>function get (key, callback)</h3>
<h4>@key {string} Key to retrieve for this instance.</h4>
<h4>@callback {function} <strong>Optional</strong> Continuation to respond to when complete.</h4>
<p>Retrieves the value for the specified key (if any).</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">get</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">overrides</span> <span class="o">&amp;&amp;</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">overrides</span><span class="p">,</span> <span class="nx">key</span><span class="p">))</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">callback</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">overrides</span><span class="p">[</span><span class="nx">key</span><span class="p">]);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">overrides</span><span class="p">[</span><span class="nx">key</span><span class="p">];</span>
<span class="p">}</span>
<p>Retrieves the value for the specified key (if any).</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">get</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>If there is no callback we can short-circuit into the default
logic for traversing stores.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">_execute</span><span class="p">(</span><span class="s1">&#39;get&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="nx">key</span><span class="p">,</span> <span class="nx">callback</span><span class="p">);</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <h3>function set (key, value, callback)</h3>
<span class="p">}</span>
</pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <p>Otherwise the asynchronous, hierarchical <code>get</code> is
slightly more complicated because we do not need to traverse
the entire set of stores, but up until there is a defined value.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">current</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span>
<span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">,</span>
<span class="nx">response</span><span class="p">;</span>
<span class="nx">async</span><span class="p">.</span><span class="nx">whilst</span><span class="p">(</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">typeof</span> <span class="nx">response</span> <span class="o">===</span> <span class="s1">&#39;undefined&#39;</span> <span class="o">&amp;&amp;</span> <span class="nx">current</span> <span class="o">&lt;</span> <span class="nx">self</span><span class="p">.</span><span class="nx">_stores</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span>
<span class="p">},</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">next</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">store</span> <span class="o">=</span> <span class="nx">self</span><span class="p">[</span><span class="nx">self</span><span class="p">.</span><span class="nx">_stores</span><span class="p">[</span><span class="nx">current</span><span class="p">]];</span>
<span class="nx">current</span><span class="o">++</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">store</span><span class="p">.</span><span class="nx">get</span><span class="p">.</span><span class="nx">length</span> <span class="o">&gt;=</span> <span class="mi">2</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">store</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">value</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">next</span><span class="p">(</span><span class="nx">err</span><span class="p">);</span>
<span class="p">}</span>
<span class="nx">response</span> <span class="o">=</span> <span class="nx">value</span><span class="p">;</span>
<span class="nx">next</span><span class="p">();</span>
<span class="p">});</span>
<span class="p">}</span>
<span class="nx">response</span> <span class="o">=</span> <span class="nx">store</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">key</span><span class="p">);</span>
<span class="nx">next</span><span class="p">();</span>
<span class="p">},</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">err</span> <span class="o">?</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="o">:</span> <span class="nx">callback</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="nx">response</span><span class="p">);</span>
<span class="p">});</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">&#182;</a> </div> <h3>function set (key, value, callback)</h3>
<h4>@key {string} Key to set in this instance</h4>
@ -68,7 +177,21 @@ specified <code>type</code>.</p> </td> <td class="code">
<p>Sets the <code>value</code> for the specified <code>key</code> in this instance.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">set</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">_execute</span><span class="p">(</span><span class="s1">&#39;set&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="nx">key</span><span class="p">,</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">callback</span><span class="p">);</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <h3>function merge ([key,] value [, callback])</h3>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">&#182;</a> </div> <h3>function reset (callback)</h3>
<h4>@callback {function} <strong>Optional</strong> Continuation to respond to when complete.</h4>
<p>Clears all keys associated with this instance.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">reset</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">_execute</span><span class="p">(</span><span class="s1">&#39;reset&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">callback</span><span class="p">);</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#182;</a> </div> <h3>function clear (key, callback)</h3>
<h4>@key {string} Key to remove from this instance</h4>
<h4>@callback {function} <strong>Optional</strong> Continuation to respond to when complete.</h4>
<p>Removes the value for the specified <code>key</code> from this instance.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">clear</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">_execute</span><span class="p">(</span><span class="s1">&#39;clear&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="nx">key</span><span class="p">,</span> <span class="nx">callback</span><span class="p">);</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">&#182;</a> </div> <h3>function merge ([key,] value [, callback])</h3>
<h4>@key {string} Key to merge the value into</h4>
@ -101,43 +224,44 @@ specified <code>type</code>.</p> </td> <td class="code">
<span class="p">}</span>
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">_execute</span><span class="p">(</span><span class="s1">&#39;merge&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="nx">key</span><span class="p">,</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">callback</span><span class="p">);</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <h3>function mergeFiles (files, callback)</h3>
<h4>@files {Object|Array} List of files (or settings object) to load.</h4>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">&#182;</a> </div> <h3>function load (callback)</h3>
<h4>@callback {function} Continuation to respond to when complete.</h4>
<p>Merges all <code>key:value</code> pairs in the <code>files</code> supplied into the
store that is managed by this provider instance.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">mergeFiles</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">files</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<p>Responds with an Object representing all keys associated in this instance.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">load</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span>
<span class="nx">common</span><span class="p">.</span><span class="nx">loadFiles</span><span class="p">(</span><span class="nx">files</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">merged</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="o">!</span><span class="nx">err</span>
<span class="o">?</span> <span class="nx">self</span><span class="p">.</span><span class="nx">merge</span><span class="p">(</span><span class="nx">merged</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span>
<span class="o">:</span> <span class="nx">onError</span><span class="p">(</span><span class="nx">err</span><span class="p">);</span>
<span class="p">});</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <h3>function clear (key, callback)</h3>
<span class="kd">function</span> <span class="nx">loadStoreSync</span><span class="p">(</span><span class="nx">name</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">store</span> <span class="o">=</span> <span class="nx">self</span><span class="p">[</span><span class="nx">name</span><span class="p">];</span>
<h4>@key {string} Key to remove from this instance</h4>
<h4>@callback {function} <strong>Optional</strong> Continuation to respond to when complete.</h4>
<p>Removes the value for the specified <code>key</code> from this instance.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">clear</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">_execute</span><span class="p">(</span><span class="s1">&#39;clear&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="nx">key</span><span class="p">,</span> <span class="nx">callback</span><span class="p">);</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <h3>function load (callback)</h3>
<h4>@callback {function} Continuation to respond to when complete.</h4>
<p>Responds with an Object representing all keys associated in this instance.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">load</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">callback</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>If we don't have a callback and the current
store is capable of loading synchronously
then do so.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">callback</span> <span class="o">&amp;&amp;</span> <span class="k">this</span><span class="p">.</span><span class="nx">store</span><span class="p">.</span><span class="nx">loadSync</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">store</span><span class="p">.</span><span class="nx">loadSync</span><span class="p">();</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">store</span><span class="p">.</span><span class="nx">loadSync</span><span class="p">)</span> <span class="p">{</span>
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s1">&#39;nconf store &#39;</span> <span class="o">+</span> <span class="nx">store</span><span class="p">.</span><span class="nx">type</span> <span class="o">+</span> <span class="s1">&#39; has no loadSync() method&#39;</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="o">!</span><span class="k">this</span><span class="p">.</span><span class="nx">store</span><span class="p">.</span><span class="nx">load</span>
<span class="o">?</span> <span class="nx">onError</span><span class="p">(</span><span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s1">&#39;nconf store &#39;</span> <span class="o">+</span> <span class="k">this</span><span class="p">.</span><span class="nx">store</span><span class="p">.</span><span class="nx">type</span> <span class="o">+</span> <span class="s1">&#39; has no load() method&#39;</span><span class="p">),</span> <span class="nx">callback</span><span class="p">)</span>
<span class="o">:</span> <span class="k">this</span><span class="p">.</span><span class="nx">store</span><span class="p">.</span><span class="nx">load</span><span class="p">(</span><span class="nx">callback</span><span class="p">);</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <h3>function save (value, callback)</h3>
<span class="k">return</span> <span class="nx">store</span><span class="p">.</span><span class="nx">loadSync</span><span class="p">();</span>
<span class="p">}</span>
<span class="kd">function</span> <span class="nx">loadStore</span><span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">next</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">store</span> <span class="o">=</span> <span class="nx">self</span><span class="p">[</span><span class="nx">name</span><span class="p">];</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">store</span><span class="p">.</span><span class="nx">load</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="nx">store</span><span class="p">.</span><span class="nx">loadSync</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">next</span><span class="p">(</span><span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s1">&#39;nconf store &#39;</span> <span class="o">+</span> <span class="nx">store</span><span class="p">.</span><span class="nx">type</span> <span class="o">+</span> <span class="s1">&#39; has no load() method&#39;</span><span class="p">));</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">store</span><span class="p">.</span><span class="nx">loadSync</span>
<span class="o">?</span> <span class="nx">next</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="nx">store</span><span class="p">.</span><span class="nx">loadSync</span><span class="p">())</span>
<span class="o">:</span> <span class="nx">store</span><span class="p">.</span><span class="nx">load</span><span class="p">(</span><span class="nx">next</span><span class="p">);</span>
<span class="p">}</span>
</pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-17">&#182;</a> </div> <p>If we don't have a callback and the current
store is capable of loading synchronously
then do so.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">common</span><span class="p">.</span><span class="nx">merge</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">_stores</span><span class="p">.</span><span class="nx">map</span><span class="p">(</span><span class="nx">loadStoreSync</span><span class="p">));</span>
<span class="p">}</span>
<span class="nx">async</span><span class="p">.</span><span class="nx">map</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">_stores</span><span class="p">,</span> <span class="nx">loadStore</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">objs</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">err</span> <span class="o">?</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="o">:</span> <span class="nx">callback</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="nx">common</span><span class="p">.</span><span class="nx">merge</span><span class="p">(</span><span class="nx">objs</span><span class="p">));</span>
<span class="p">});</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-18"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-18">&#182;</a> </div> <h3>function save (value, callback)</h3>
<h4>@value {Object} <strong>Optional</strong> Config object to set for this instance</h4>
@ -145,26 +269,44 @@ then do so.</p> </td> <td class="code"> <d
<p>Removes any existing configuration settings that may exist in this
instance and then adds all key-value pairs in <code>value</code>. </p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">save</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">value</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">callback</span> <span class="o">&amp;&amp;</span> <span class="k">typeof</span> <span class="nx">value</span> <span class="o">===</span> <span class="s1">&#39;function&#39;</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">callback</span> <span class="o">=</span> <span class="nx">value</span><span class="p">;</span>
<span class="nx">value</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
</pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">&#182;</a> </div> <p>If we still don't have a callback and the
current store is capable of saving synchronously
then do so.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">callback</span> <span class="o">&amp;&amp;</span> <span class="k">this</span><span class="p">.</span><span class="nx">store</span><span class="p">.</span><span class="nx">saveSync</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">store</span><span class="p">.</span><span class="nx">saveSync</span><span class="p">();</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">return</span> <span class="o">!</span><span class="k">this</span><span class="p">.</span><span class="nx">store</span><span class="p">.</span><span class="nx">save</span>
<span class="o">?</span> <span class="nx">onError</span><span class="p">(</span><span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s1">&#39;nconf store &#39;</span> <span class="o">+</span> <span class="k">this</span><span class="p">.</span><span class="nx">store</span><span class="p">.</span><span class="nx">type</span> <span class="o">+</span> <span class="s1">&#39; has no save() method&#39;</span><span class="p">),</span> <span class="nx">callback</span><span class="p">)</span>
<span class="o">:</span> <span class="k">this</span><span class="p">.</span><span class="nx">store</span><span class="p">.</span><span class="nx">save</span><span class="p">(</span><span class="nx">value</span><span class="p">,</span> <span class="nx">callback</span><span class="p">);</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">&#182;</a> </div> <h3>function reset (callback)</h3>
<span class="kd">var</span> <span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span>
<h4>@callback {function} <strong>Optional</strong> Continuation to respond to when complete.</h4>
<span class="kd">function</span> <span class="nx">saveStoreSync</span><span class="p">(</span><span class="nx">name</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">store</span> <span class="o">=</span> <span class="nx">self</span><span class="p">[</span><span class="nx">name</span><span class="p">];</span>
<p>Clears all keys associated with this instance.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">reset</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">_execute</span><span class="p">(</span><span class="s1">&#39;reset&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">callback</span><span class="p">);</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#182;</a> </div> <h3>@private function _execute (action, syncLength, [arguments])</h3>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">store</span><span class="p">.</span><span class="nx">saveSync</span><span class="p">)</span> <span class="p">{</span>
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s1">&#39;nconf store &#39;</span> <span class="o">+</span> <span class="nx">store</span><span class="p">.</span><span class="nx">type</span> <span class="o">+</span> <span class="s1">&#39; has no saveSync() method&#39;</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">store</span><span class="p">.</span><span class="nx">saveSync</span><span class="p">();</span>
<span class="p">}</span>
<span class="kd">function</span> <span class="nx">saveStore</span><span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">next</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">store</span> <span class="o">=</span> <span class="nx">self</span><span class="p">[</span><span class="nx">name</span><span class="p">];</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">store</span><span class="p">.</span><span class="nx">save</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="nx">store</span><span class="p">.</span><span class="nx">saveSync</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">next</span><span class="p">(</span><span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s1">&#39;nconf store &#39;</span> <span class="o">+</span> <span class="nx">store</span><span class="p">.</span><span class="nx">type</span> <span class="o">+</span> <span class="s1">&#39; has no save() method&#39;</span><span class="p">));</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">store</span><span class="p">.</span><span class="nx">saveSync</span>
<span class="o">?</span> <span class="nx">next</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="nx">store</span><span class="p">.</span><span class="nx">saveSync</span><span class="p">())</span>
<span class="o">:</span> <span class="nx">store</span><span class="p">.</span><span class="nx">save</span><span class="p">(</span><span class="nx">next</span><span class="p">);</span>
<span class="p">}</span>
</pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-19">&#182;</a> </div> <p>If we don't have a callback and the current
store is capable of saving synchronously
then do so.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">common</span><span class="p">.</span><span class="nx">merge</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">_stores</span><span class="p">.</span><span class="nx">map</span><span class="p">(</span><span class="nx">saveStoreSync</span><span class="p">));</span>
<span class="p">}</span>
<span class="nx">async</span><span class="p">.</span><span class="nx">map</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">_stores</span><span class="p">,</span> <span class="nx">saveStore</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">objs</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">err</span> <span class="o">?</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="o">:</span> <span class="nx">callback</span><span class="p">();</span>
<span class="p">});</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-20"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-20">&#182;</a> </div> <h3>@private function _execute (action, syncLength, [arguments])</h3>
<h4>@action {string} Action to execute on <code>this.store</code>.</h4>
@ -172,41 +314,65 @@ then do so.</p> </td> <td class="code"> <d
<h4>@arguments {Array} Arguments array to apply to the action</h4>
<p>Executes the specified <code>action</code> on <code>this.store</code>, ensuring a callback supplied
<p>Executes the specified <code>action</code> on all stores for this instance, ensuring a callback supplied
to a synchronous store function is still invoked.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">_execute</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">action</span><span class="p">,</span> <span class="nx">syncLength</span> <span class="cm">/* [arguments] */</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">args</span> <span class="o">=</span> <span class="nb">Array</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">slice</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">arguments</span><span class="p">,</span> <span class="mi">2</span><span class="p">),</span>
<span class="nx">callback</span><span class="p">,</span>
<span class="nx">callback</span> <span class="o">=</span> <span class="k">typeof</span> <span class="nx">args</span><span class="p">[</span><span class="nx">args</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">===</span> <span class="s1">&#39;function&#39;</span> <span class="o">&amp;&amp;</span> <span class="nx">args</span><span class="p">.</span><span class="nx">pop</span><span class="p">(),</span>
<span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">,</span>
<span class="nx">response</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">store</span><span class="p">[</span><span class="nx">action</span><span class="p">].</span><span class="nx">length</span> <span class="o">&gt;</span> <span class="nx">syncLength</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">store</span><span class="p">[</span><span class="nx">action</span><span class="p">].</span><span class="nx">apply</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">store</span><span class="p">,</span> <span class="nx">args</span><span class="p">);</span>
<span class="p">}</span>
<span class="kd">function</span> <span class="nx">runAction</span> <span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">next</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">store</span> <span class="o">=</span> <span class="nx">self</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span>
<span class="nx">callback</span> <span class="o">=</span> <span class="k">typeof</span> <span class="nx">args</span><span class="p">[</span><span class="nx">args</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="o">===</span> <span class="s1">&#39;function&#39;</span> <span class="o">&amp;&amp;</span> <span class="nx">args</span><span class="p">.</span><span class="nx">pop</span><span class="p">();</span>
<span class="nx">response</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">store</span><span class="p">[</span><span class="nx">action</span><span class="p">].</span><span class="nx">apply</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">store</span><span class="p">,</span> <span class="nx">args</span><span class="p">);</span>
<span class="k">return</span> <span class="nx">store</span><span class="p">[</span><span class="nx">action</span><span class="p">].</span><span class="nx">length</span> <span class="o">&gt;</span> <span class="nx">syncLength</span>
<span class="o">?</span> <span class="nx">store</span><span class="p">[</span><span class="nx">action</span><span class="p">].</span><span class="nx">apply</span><span class="p">(</span><span class="nx">store</span><span class="p">,</span> <span class="nx">args</span><span class="p">.</span><span class="nx">concat</span><span class="p">(</span><span class="nx">next</span><span class="p">))</span>
<span class="o">:</span> <span class="nx">next</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="nx">store</span><span class="p">[</span><span class="nx">action</span><span class="p">].</span><span class="nx">apply</span><span class="p">(</span><span class="nx">store</span><span class="p">,</span> <span class="nx">args</span><span class="p">));</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">callback</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="nx">response</span><span class="p">);</span>
<span class="k">return</span> <span class="nx">async</span><span class="p">.</span><span class="nx">forEach</span><span class="p">(</span><span class="nx">self</span><span class="p">.</span><span class="nx">_stores</span><span class="p">,</span> <span class="nx">runAction</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">err</span> <span class="o">?</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="o">:</span> <span class="nx">callback</span><span class="p">();</span>
<span class="p">});</span>
<span class="p">}</span>
<span class="k">this</span><span class="p">.</span><span class="nx">_stores</span><span class="p">.</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">name</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">store</span> <span class="o">=</span> <span class="nx">self</span><span class="p">[</span><span class="nx">name</span><span class="p">];</span>
<span class="nx">response</span> <span class="o">=</span> <span class="nx">store</span><span class="p">[</span><span class="nx">action</span><span class="p">].</span><span class="nx">apply</span><span class="p">(</span><span class="nx">store</span><span class="p">,</span> <span class="nx">args</span><span class="p">);</span>
<span class="p">});</span>
<span class="k">return</span> <span class="nx">response</span><span class="p">;</span>
<span class="p">}</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">&#182;</a> </div> <h3>getter @useArgv {boolean}</h3>
<span class="p">}</span></pre></div> </td> </tr> <tr id="section-21"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-21">&#182;</a> </div> <h3>@argv {boolean}</h3>
<p>Gets a property indicating if we should wrap calls to <code>.get</code>
by checking <code>optimist.argv</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">__defineGetter__</span><span class="p">(</span><span class="s1">&#39;useArgv&#39;</span><span class="p">,</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">_useArgv</span><span class="p">;</span>
<span class="p">});</span></pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">&#182;</a> </div> <h3>setter @useArgv {boolean}</h3>
<p>Gets or sets a property representing overrides which supercede all
other values for this instance.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">__defineSetter__</span><span class="p">(</span><span class="s1">&#39;overrides&#39;</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">val</span><span class="p">)</span> <span class="p">{</span> <span class="nx">updateSystem</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="s1">&#39;overrides&#39;</span><span class="p">,</span> <span class="nx">val</span><span class="p">)</span> <span class="p">});</span>
<span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">__defineGetter__</span><span class="p">(</span><span class="s1">&#39;overrides&#39;</span><span class="p">,</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> <span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">_argv</span> <span class="p">});</span></pre></div> </td> </tr> <tr id="section-22"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-22">&#182;</a> </div> <h3>@argv {boolean}</h3>
<p>Sets a property indicating if we should wrap calls to <code>.get</code>
by checking <code>optimist.argv</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">__defineSetter__</span><span class="p">(</span><span class="s1">&#39;useArgv&#39;</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">val</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">_useArgv</span> <span class="o">=</span> <span class="nx">val</span> <span class="o">||</span> <span class="kc">false</span><span class="p">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">overrides</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">overrides</span> <span class="o">||</span> <span class="nx">optimist</span><span class="p">.</span><span class="nx">argv</span><span class="p">;</span>
<span class="p">});</span></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-17">&#182;</a> </div> <p>Throw the <code>err</code> if a callback is not supplied</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">onError</span><span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<p>Gets or sets a property indicating if we should wrap calls to <code>.get</code>
by checking <code>optimist.argv</code>. Can be a boolean or the pass-thru
options for <code>optimist</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">__defineSetter__</span><span class="p">(</span><span class="s1">&#39;argv&#39;</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">val</span><span class="p">)</span> <span class="p">{</span> <span class="nx">updateSystem</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="s1">&#39;argv&#39;</span><span class="p">,</span> <span class="nx">val</span><span class="p">)</span> <span class="p">});</span>
<span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">__defineGetter__</span><span class="p">(</span><span class="s1">&#39;argv&#39;</span><span class="p">,</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> <span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">_argv</span> <span class="p">});</span></pre></div> </td> </tr> <tr id="section-23"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-23">&#182;</a> </div> <h3>@env {boolean}</h3>
<p>Gets or sets a property indicating if we should wrap calls to <code>.get</code>
by checking <code>process.env</code>. Can be a boolean or an Array of
environment variables to extract.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">__defineSetter__</span><span class="p">(</span><span class="s1">&#39;env&#39;</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">val</span><span class="p">)</span> <span class="p">{</span> <span class="nx">updateSystem</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="s1">&#39;env&#39;</span><span class="p">,</span> <span class="nx">val</span><span class="p">)</span> <span class="p">});</span>
<span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">__defineGetter__</span><span class="p">(</span><span class="s1">&#39;env&#39;</span><span class="p">,</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> <span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">_env</span> <span class="p">});</span></pre></div> </td> </tr> <tr id="section-24"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-24">&#182;</a> </div> <p>Throw the <code>err</code> if a callback is not supplied</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">onError</span><span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">err</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">throw</span> <span class="nx">err</span><span class="p">;</span>
<span class="p">}</span></pre></div> </td> </tr> <tr id="section-25"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-25">&#182;</a> </div> <p>Helper function for working with the
default <code>system</code> store for providers.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">function</span> <span class="nx">updateSystem</span><span class="p">(</span><span class="nx">prop</span><span class="p">,</span> <span class="nx">value</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">system</span> <span class="o">=</span> <span class="k">this</span><span class="p">[</span><span class="s1">&#39;system&#39;</span><span class="p">];</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">system</span><span class="p">[</span><span class="nx">prop</span><span class="p">]</span> <span class="o">===</span> <span class="nx">value</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
<span class="nx">value</span> <span class="o">=</span> <span class="nx">value</span> <span class="o">||</span> <span class="kc">false</span><span class="p">;</span>
<span class="k">this</span><span class="p">[</span><span class="s1">&#39;_&#39;</span> <span class="o">+</span> <span class="nx">prop</span><span class="p">]</span> <span class="o">=</span> <span class="nx">value</span><span class="p">;</span>
<span class="nx">system</span><span class="p">[</span><span class="nx">prop</span><span class="p">]</span> <span class="o">=</span> <span class="nx">value</span><span class="p">;</span>
<span class="nx">system</span><span class="p">.</span><span class="nx">loadSync</span><span class="p">();</span>
<span class="p">}</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>

View file

@ -1,4 +1,4 @@
<!DOCTYPE html> <html> <head> <title>stores.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="../docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="..//nconf/common.html"> nconf/common.html </a> <a class="source" href="..//nconf/formats.html"> nconf/formats.html </a> <a class="source" href="..//nconf/provider.html"> nconf/provider.html </a> <a class="source" href="..//nconf/stores/file.html"> nconf/stores/file.html </a> <a class="source" href="..//nconf/stores/memory.html"> nconf/stores/memory.html </a> <a class="source" href="..//nconf/stores.html"> nconf/stores.html </a> <a class="source" href="..//nconf.html"> nconf.html </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> stores.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
<!DOCTYPE html> <html> <head> <title>stores.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="../docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="..//nconf/common.html"> nconf/common.html </a> <a class="source" href="..//nconf/formats.html"> nconf/formats.html </a> <a class="source" href="..//nconf/provider.html"> nconf/provider.html </a> <a class="source" href="..//nconf/stores/file.html"> nconf/stores/file.html </a> <a class="source" href="..//nconf/stores/memory.html"> nconf/stores/memory.html </a> <a class="source" href="..//nconf/stores/system.html"> nconf/stores/system.html </a> <a class="source" href="..//nconf/stores.html"> nconf/stores.html </a> <a class="source" href="..//nconf.html"> nconf.html </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> stores.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
<span class="cm"> * stores.js: Top-level include for all nconf stores</span>
<span class="cm"> *</span>
<span class="cm"> * (C) 2011, Charlie Robbins</span>
@ -6,26 +6,14 @@
<span class="cm"> */</span>
<span class="kd">var</span> <span class="nx">fs</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;fs&#39;</span><span class="p">),</span>
<span class="nx">stores</span> <span class="o">=</span> <span class="nx">exports</span><span class="p">;</span>
<span class="kd">function</span> <span class="nx">capitalize</span> <span class="p">(</span><span class="nx">str</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">str</span> <span class="o">&amp;&amp;</span> <span class="nx">str</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">toUpperCase</span><span class="p">()</span> <span class="o">+</span> <span class="nx">str</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>Setup all stores as lazy-loaded getters.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">fs</span><span class="p">.</span><span class="nx">readdirSync</span><span class="p">(</span><span class="nx">__dirname</span> <span class="o">+</span> <span class="s1">&#39;/stores&#39;</span><span class="p">).</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">file</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">common</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./common&#39;</span><span class="p">),</span>
<span class="nx">stores</span> <span class="o">=</span> <span class="nx">exports</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>Setup all stores as lazy-loaded getters.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">fs</span><span class="p">.</span><span class="nx">readdirSync</span><span class="p">(</span><span class="nx">__dirname</span> <span class="o">+</span> <span class="s1">&#39;/stores&#39;</span><span class="p">).</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">file</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">store</span> <span class="o">=</span> <span class="nx">file</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="s1">&#39;.js&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">),</span>
<span class="nx">name</span> <span class="o">=</span> <span class="nx">capitalize</span><span class="p">(</span><span class="nx">store</span><span class="p">);</span>
<span class="nx">name</span> <span class="o">=</span> <span class="nx">common</span><span class="p">.</span><span class="nx">capitalize</span><span class="p">(</span><span class="nx">store</span><span class="p">);</span>
<span class="nx">stores</span><span class="p">.</span><span class="nx">__defineGetter__</span><span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./stores/&#39;</span> <span class="o">+</span> <span class="nx">store</span><span class="p">)[</span><span class="nx">name</span><span class="p">];</span>
<span class="p">});</span>
<span class="p">});</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <h3>function create (type, options)</h3>
<h4>@type {string} Type of the nconf store to use.</h4>
<h4>@options {Object} Options for the store instance.</h4>
<p>Creates a store of the specified <code>type</code> using the
specified <code>options</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">stores</span><span class="p">.</span><span class="nx">create</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">type</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">new</span> <span class="nx">stores</span><span class="p">[</span><span class="nx">capitalize</span><span class="p">(</span><span class="nx">type</span><span class="p">.</span><span class="nx">toLowerCase</span><span class="p">())](</span><span class="nx">options</span><span class="p">);</span>
<span class="p">};</span>
<span class="p">});</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>

View file

@ -1,4 +1,4 @@
<!DOCTYPE html> <html> <head> <title>file.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="../../docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="../..//nconf/common.html"> nconf/common.html </a> <a class="source" href="../..//nconf/formats.html"> nconf/formats.html </a> <a class="source" href="../..//nconf/provider.html"> nconf/provider.html </a> <a class="source" href="../..//nconf/stores/file.html"> nconf/stores/file.html </a> <a class="source" href="../..//nconf/stores/memory.html"> nconf/stores/memory.html </a> <a class="source" href="../..//nconf/stores.html"> nconf/stores.html </a> <a class="source" href="../..//nconf.html"> nconf.html </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> file.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
<!DOCTYPE html> <html> <head> <title>file.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="../../docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="../..//nconf/common.html"> nconf/common.html </a> <a class="source" href="../..//nconf/formats.html"> nconf/formats.html </a> <a class="source" href="../..//nconf/provider.html"> nconf/provider.html </a> <a class="source" href="../..//nconf/stores/file.html"> nconf/stores/file.html </a> <a class="source" href="../..//nconf/stores/memory.html"> nconf/stores/memory.html </a> <a class="source" href="../..//nconf/stores/system.html"> nconf/stores/system.html </a> <a class="source" href="../..//nconf/stores.html"> nconf/stores.html </a> <a class="source" href="../..//nconf.html"> nconf.html </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> file.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
<span class="cm"> * file.js: Simple file storage engine for nconf files</span>
<span class="cm"> *</span>
<span class="cm"> * (C) 2011, Charlie Robbins</span>
@ -16,7 +16,7 @@
<p>Constructor function for the File nconf store, a simple abstraction
around the Memory store that can persist configuration to disk.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">File</span> <span class="o">=</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">File</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">options</span><span class="p">.</span><span class="nx">file</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">options</span> <span class="o">||</span> <span class="o">!</span><span class="nx">options</span><span class="p">.</span><span class="nx">file</span><span class="p">)</span> <span class="p">{</span>
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="p">(</span><span class="s1">&#39;Missing required option `files`&#39;</span><span class="p">);</span>
<span class="p">}</span>
@ -97,8 +97,8 @@ using the format specified by <code>this.format</code> synchronously.</p>
<span class="nx">data</span> <span class="o">=</span> <span class="p">{};</span>
<span class="p">}</span>
<span class="k">else</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <p>Else, the path exists, read it from disk</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">try</span> <span class="p">{</span>
<span class="nx">data</span> <span class="o">=</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">readFileSync</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">file</span><span class="p">,</span> <span class="s1">&#39;utf8&#39;</span><span class="p">);</span>
<span class="k">this</span><span class="p">.</span><span class="nx">store</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">format</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="nx">data</span><span class="p">);</span>
<span class="nx">data</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">format</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="nx">fs</span><span class="p">.</span><span class="nx">readFileSync</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">file</span><span class="p">,</span> <span class="s1">&#39;utf8&#39;</span><span class="p">));</span>
<span class="k">this</span><span class="p">.</span><span class="nx">store</span> <span class="o">=</span> <span class="nx">data</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">catch</span> <span class="p">(</span><span class="nx">ex</span><span class="p">)</span> <span class="p">{</span>
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s2">&quot;Error parsing your JSON configuration file.&quot;</span><span class="p">)</span>

View file

@ -1,11 +1,11 @@
<!DOCTYPE html> <html> <head> <title>memory.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="../../docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="../..//nconf/common.html"> nconf/common.html </a> <a class="source" href="../..//nconf/formats.html"> nconf/formats.html </a> <a class="source" href="../..//nconf/provider.html"> nconf/provider.html </a> <a class="source" href="../..//nconf/stores/file.html"> nconf/stores/file.html </a> <a class="source" href="../..//nconf/stores/memory.html"> nconf/stores/memory.html </a> <a class="source" href="../..//nconf/stores.html"> nconf/stores.html </a> <a class="source" href="../..//nconf.html"> nconf.html </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> memory.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
<!DOCTYPE html> <html> <head> <title>memory.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="../../docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="../..//nconf/common.html"> nconf/common.html </a> <a class="source" href="../..//nconf/formats.html"> nconf/formats.html </a> <a class="source" href="../..//nconf/provider.html"> nconf/provider.html </a> <a class="source" href="../..//nconf/stores/file.html"> nconf/stores/file.html </a> <a class="source" href="../..//nconf/stores/memory.html"> nconf/stores/memory.html </a> <a class="source" href="../..//nconf/stores/system.html"> nconf/stores/system.html </a> <a class="source" href="../..//nconf/stores.html"> nconf/stores.html </a> <a class="source" href="../..//nconf.html"> nconf.html </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> memory.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
<span class="cm"> * memory.js: Simple memory storage engine for nconf configuration(s)</span>
<span class="cm"> *</span>
<span class="cm"> * (C) 2011, Charlie Robbins</span>
<span class="cm"> *</span>
<span class="cm"> */</span>
<span class="kd">var</span> <span class="nx">nconf</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;../../nconf&#39;</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <h3>function Memory (options)</h3>
<span class="kd">var</span> <span class="nx">common</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;../common&#39;</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <h3>function Memory (options)</h3>
<h4>@options {Object} Options for this instance</h4>
@ -17,13 +17,19 @@ a nested json structure based on key delimiters <code>:</code>.</p>
<span class="k">this</span><span class="p">.</span><span class="nx">type</span> <span class="o">=</span> <span class="s1">&#39;memory&#39;</span><span class="p">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">store</span> <span class="o">=</span> <span class="p">{};</span>
<span class="k">this</span><span class="p">.</span><span class="nx">mtimes</span> <span class="o">=</span> <span class="p">{};</span>
<span class="k">this</span><span class="p">.</span><span class="nx">readOnly</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">loadFrom</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">loadFrom</span> <span class="o">||</span> <span class="kc">null</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">loadFrom</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">store</span> <span class="o">=</span> <span class="nx">common</span><span class="p">.</span><span class="nx">loadFilesSync</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">loadFrom</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <h3>function get (key)</h3>
<h4>@key {string} Key to retrieve for this instance.</h4>
<p>Retrieves the value for the specified key (if any).</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Memory</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">get</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">target</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">store</span><span class="p">,</span>
<span class="nx">path</span> <span class="o">=</span> <span class="nx">nconf</span><span class="p">.</span><span class="nx">path</span><span class="p">(</span><span class="nx">key</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>Scope into the object to get the appropriate nested context</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">while</span> <span class="p">(</span><span class="nx">path</span><span class="p">.</span><span class="nx">length</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">path</span> <span class="o">=</span> <span class="nx">common</span><span class="p">.</span><span class="nx">path</span><span class="p">(</span><span class="nx">key</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>Scope into the object to get the appropriate nested context</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">while</span> <span class="p">(</span><span class="nx">path</span><span class="p">.</span><span class="nx">length</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">key</span> <span class="o">=</span> <span class="nx">path</span><span class="p">.</span><span class="nx">shift</span><span class="p">();</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="p">(</span><span class="nx">target</span> <span class="o">&amp;&amp;</span> <span class="nx">key</span> <span class="k">in</span> <span class="nx">target</span><span class="p">))</span> <span class="p">{</span>
<span class="k">return</span><span class="p">;</span>
@ -41,8 +47,12 @@ a nested json structure based on key delimiters <code>:</code>.</p>
<h4>@value {literal|Object} Value for the specified key</h4>
<p>Sets the <code>value</code> for the specified <code>key</code> in this instance.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Memory</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">set</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">value</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">readOnly</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="kd">var</span> <span class="nx">target</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">store</span><span class="p">,</span>
<span class="nx">path</span> <span class="o">=</span> <span class="nx">nconf</span><span class="p">.</span><span class="nx">path</span><span class="p">(</span><span class="nx">key</span><span class="p">);</span>
<span class="nx">path</span> <span class="o">=</span> <span class="nx">common</span><span class="p">.</span><span class="nx">path</span><span class="p">(</span><span class="nx">key</span><span class="p">);</span>
</pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Update the <code>mtime</code> (modified time) of the key</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">mtimes</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="nb">Date</span><span class="p">.</span><span class="nx">now</span><span class="p">();</span>
</pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Scope into the object to get the appropriate nested context</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">while</span> <span class="p">(</span><span class="nx">path</span><span class="p">.</span><span class="nx">length</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">key</span> <span class="o">=</span> <span class="nx">path</span><span class="p">.</span><span class="nx">shift</span><span class="p">();</span>
@ -60,8 +70,12 @@ a nested json structure based on key delimiters <code>:</code>.</p>
<h4>@key {string} Key to remove from this instance</h4>
<p>Removes the value for the specified <code>key</code> from this instance.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Memory</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">clear</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">readOnly</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="kd">var</span> <span class="nx">target</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">store</span><span class="p">,</span>
<span class="nx">path</span> <span class="o">=</span> <span class="nx">nconf</span><span class="p">.</span><span class="nx">path</span><span class="p">(</span><span class="nx">key</span><span class="p">);</span>
<span class="nx">path</span> <span class="o">=</span> <span class="nx">common</span><span class="p">.</span><span class="nx">path</span><span class="p">(</span><span class="nx">key</span><span class="p">);</span>
</pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>Remove the key from the set of <code>mtimes</code> (modified times)</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">delete</span> <span class="k">this</span><span class="p">.</span><span class="nx">mtimes</span><span class="p">[</span><span class="nx">key</span><span class="p">];</span>
</pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <p>Scope into the object to get the appropriate nested context</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">while</span> <span class="p">(</span><span class="nx">path</span><span class="p">.</span><span class="nx">length</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">key</span> <span class="o">=</span> <span class="nx">path</span><span class="p">.</span><span class="nx">shift</span><span class="p">();</span>
@ -82,14 +96,18 @@ a nested json structure based on key delimiters <code>:</code>.</p>
<p>Merges the properties in <code>value</code> into the existing object value
at <code>key</code>. If the existing value <code>key</code> is not an Object, it will be
completely overwritten.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Memory</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">merge</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">value</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#182;</a> </div> <p>If the key is not an <code>Object</code> or is an <code>Array</code>,
completely overwritten.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Memory</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">merge</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">value</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">readOnly</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
<span class="p">}</span>
</pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#182;</a> </div> <p>If the key is not an <code>Object</code> or is an <code>Array</code>,
then simply set it. Merging is for Objects.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">value</span> <span class="o">!==</span> <span class="s1">&#39;object&#39;</span> <span class="o">||</span> <span class="nb">Array</span><span class="p">.</span><span class="nx">isArray</span><span class="p">(</span><span class="nx">value</span><span class="p">))</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">value</span><span class="p">);</span>
<span class="p">}</span>
<span class="kd">var</span> <span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">,</span>
<span class="nx">target</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">store</span><span class="p">,</span>
<span class="nx">path</span> <span class="o">=</span> <span class="nx">nconf</span><span class="p">.</span><span class="nx">path</span><span class="p">(</span><span class="nx">key</span><span class="p">),</span>
<span class="nx">path</span> <span class="o">=</span> <span class="nx">common</span><span class="p">.</span><span class="nx">path</span><span class="p">(</span><span class="nx">key</span><span class="p">),</span>
<span class="nx">fullKey</span> <span class="o">=</span> <span class="nx">key</span><span class="p">;</span>
</pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">&#182;</a> </div> <p>Update the <code>mtime</code> (modified time) of the key</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">mtimes</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="nb">Date</span><span class="p">.</span><span class="nx">now</span><span class="p">();</span>
</pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">&#182;</a> </div> <p>Scope into the object to get the appropriate nested context</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">while</span> <span class="p">(</span><span class="nx">path</span><span class="p">.</span><span class="nx">length</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
@ -113,6 +131,10 @@ is an Object.</p> </td> <td class="code">
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-19">&#182;</a> </div> <h3>function reset (callback)</h3>
<p>Clears all keys associated with this instance.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Memory</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">reset</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">readOnly</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">this</span><span class="p">.</span><span class="nx">mtimes</span> <span class="o">=</span> <span class="p">{};</span>
<span class="k">this</span><span class="p">.</span><span class="nx">store</span> <span class="o">=</span> <span class="p">{};</span>
<span class="k">return</span> <span class="kc">true</span><span class="p">;</span>

View file

@ -1,308 +0,0 @@
<!DOCTYPE html> <html> <head> <title>redis.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="../../docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="../..//nconf/provider.html"> nconf/provider.html </a> <a class="source" href="../..//nconf/stores/file.html"> nconf/stores/file.html </a> <a class="source" href="../..//nconf/stores/memory.html"> nconf/stores/memory.html </a> <a class="source" href="../..//nconf/stores/redis.html"> nconf/stores/redis.html </a> <a class="source" href="../..//nconf/stores.html"> nconf/stores.html </a> <a class="source" href="../..//nconf.html"> nconf.html </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> redis.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
<span class="cm"> * redis.js: Redis storage engine for nconf configuration(s)</span>
<span class="cm"> *</span>
<span class="cm"> * (C) 2011, Charlie Robbins</span>
<span class="cm"> *</span>
<span class="cm"> */</span>
<span class="kd">var</span> <span class="nx">async</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;async&#39;</span><span class="p">),</span>
<span class="nx">redis</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;redis&#39;</span><span class="p">),</span>
<span class="nx">nconf</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;../../nconf&#39;</span><span class="p">),</span>
<span class="nx">Memory</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./memory&#39;</span><span class="p">).</span><span class="nx">Memory</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <h3>function Redis (options)</h3>
<h4>@options {Object} Options for this instance</h4>
<p>Constructor function for the Redis nconf store which maintains
a nested Redis key structure based on key delimiters <code>:</code>.</p>
<p>e.g.
my:nested:key, 'value'
namespace:keys ==> ['my']
namespace:nested:keys ==> ['key']
namespace:nested:key ==> 'value'</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">Redis</span> <span class="o">=</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">Redis</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">options</span> <span class="o">=</span> <span class="nx">options</span> <span class="o">||</span> <span class="p">{};</span>
<span class="k">this</span><span class="p">.</span><span class="nx">type</span> <span class="o">=</span> <span class="s1">&#39;redis&#39;</span><span class="p">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">namespace</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">namespace</span> <span class="o">||</span> <span class="s1">&#39;nconf&#39;</span><span class="p">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">host</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">host</span> <span class="o">||</span> <span class="s1">&#39;localhost&#39;</span><span class="p">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">port</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">port</span> <span class="o">||</span> <span class="mi">6379</span><span class="p">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">ttl</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">ttl</span> <span class="o">||</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">1000</span><span class="p">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">cache</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Memory</span><span class="p">();</span>
<span class="k">this</span><span class="p">.</span><span class="nx">redis</span> <span class="o">=</span> <span class="nx">redis</span><span class="p">.</span><span class="nx">createClient</span><span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">port</span><span class="p">,</span> <span class="nx">options</span><span class="p">.</span><span class="nx">host</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">auth</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">redis</span><span class="p">.</span><span class="nx">auth</span><span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">auth</span><span class="p">);</span>
<span class="p">}</span>
</pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Suppress errors from the Redis client</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">redis</span><span class="p">.</span><span class="nx">on</span><span class="p">(</span><span class="s1">&#39;error&#39;</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">dir</span><span class="p">(</span><span class="nx">err</span><span class="p">);</span>
<span class="p">});</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <h3>function get (key, callback)</h3>
<h4>@key {string} Key to retrieve for this instance.</h4>
<h4>@callback {function} Continuation to respond to when complete.</h4>
<p>Retrieves the value for the specified key (if any).</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Redis</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">get</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">,</span>
<span class="nx">result</span> <span class="o">=</span> <span class="p">{},</span>
<span class="nx">now</span> <span class="o">=</span> <span class="nb">Date</span><span class="p">.</span><span class="nx">now</span><span class="p">(),</span>
<span class="nx">mtime</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">cache</span><span class="p">.</span><span class="nx">mtimes</span><span class="p">[</span><span class="nx">key</span><span class="p">],</span>
<span class="nx">fullKey</span> <span class="o">=</span> <span class="nx">nconf</span><span class="p">.</span><span class="nx">key</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">namespace</span><span class="p">,</span> <span class="nx">key</span><span class="p">);</span>
</pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Set the callback if not provided for "fire and forget"</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">callback</span> <span class="o">=</span> <span class="nx">callback</span> <span class="o">||</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> <span class="p">};</span>
</pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>If the key exists in the cache and the ttl is less than
the value set for this instance, return from the cache.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="nx">mtime</span> <span class="o">&amp;&amp;</span> <span class="nx">now</span> <span class="o">-</span> <span class="nx">mtime</span> <span class="o">&lt;</span> <span class="k">this</span><span class="p">.</span><span class="nx">ttl</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">callback</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">cache</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">key</span><span class="p">));</span>
<span class="p">}</span>
</pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Get the set of all children keys for the <code>key</code> supplied. If the value
to be returned is an Object, this list will not be empty.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">redis</span><span class="p">.</span><span class="nx">smembers</span><span class="p">(</span><span class="nx">nconf</span><span class="p">.</span><span class="nx">key</span><span class="p">(</span><span class="nx">fullKey</span><span class="p">,</span> <span class="s1">&#39;keys&#39;</span><span class="p">),</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">keys</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">function</span> <span class="nx">addValue</span> <span class="p">(</span><span class="nx">source</span><span class="p">,</span> <span class="nx">next</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">self</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">nconf</span><span class="p">.</span><span class="nx">key</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">source</span><span class="p">),</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">value</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">next</span><span class="p">(</span><span class="nx">err</span><span class="p">);</span>
<span class="p">}</span>
<span class="nx">result</span><span class="p">[</span><span class="nx">source</span><span class="p">]</span> <span class="o">=</span> <span class="nx">value</span><span class="p">;</span>
<span class="nx">next</span><span class="p">();</span>
<span class="p">});</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">keys</span> <span class="o">&amp;&amp;</span> <span class="nx">keys</span><span class="p">.</span><span class="nx">length</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>If the value to be retrieved is an Object, recursively attempt
to get the value from redis. Here we use a recursive call to <code>this.get</code>
to support nested Object keys.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">async</span><span class="p">.</span><span class="nx">forEach</span><span class="p">(</span><span class="nx">keys</span><span class="p">,</span> <span class="nx">addValue</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">err</span><span class="p">);</span>
<span class="p">}</span>
<span class="nx">self</span><span class="p">.</span><span class="nx">cache</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">result</span><span class="p">);</span>
<span class="nx">callback</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="nx">result</span><span class="p">);</span>
<span class="p">})</span>
<span class="p">}</span>
<span class="k">else</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>If there are no keys, then the value to be retrieved is a literal
and we can simply return the value from redis directly. </p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">self</span><span class="p">.</span><span class="nx">redis</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">fullKey</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">value</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">err</span><span class="p">);</span>
<span class="p">}</span>
<span class="nx">result</span> <span class="o">=</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="nx">value</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">result</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">self</span><span class="p">.</span><span class="nx">cache</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">result</span><span class="p">);</span>
<span class="p">}</span>
<span class="nx">callback</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="nx">result</span><span class="p">);</span>
<span class="p">});</span>
<span class="p">}</span>
<span class="p">});</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <h3>function set (key, value, callback)</h3>
<h4>@key {string} Key to set in this instance</h4>
<h4>@value {literal|Object} Value for the specified key</h4>
<h4>@callback {function} Continuation to respond to when complete.</h4>
<p>Sets the <code>value</code> for the specified <code>key</code> in this instance.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Redis</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">set</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">,</span>
<span class="nx">path</span> <span class="o">=</span> <span class="nx">nconf</span><span class="p">.</span><span class="nx">path</span><span class="p">(</span><span class="nx">key</span><span class="p">);</span>
</pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <p>Set the callback if not provided for "fire and forget"</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">callback</span> <span class="o">=</span> <span class="nx">callback</span> <span class="o">||</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> <span class="p">};</span>
<span class="k">this</span><span class="p">.</span><span class="nx">_addKeys</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">err</span><span class="p">);</span>
<span class="p">}</span>
<span class="kd">var</span> <span class="nx">fullKey</span> <span class="o">=</span> <span class="nx">nconf</span><span class="p">.</span><span class="nx">key</span><span class="p">(</span><span class="nx">self</span><span class="p">.</span><span class="nx">namespace</span><span class="p">,</span> <span class="nx">key</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nb">Array</span><span class="p">.</span><span class="nx">isArray</span><span class="p">(</span><span class="nx">value</span><span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="nx">value</span> <span class="o">!==</span> <span class="kc">null</span> <span class="o">&amp;&amp;</span> <span class="k">typeof</span> <span class="nx">value</span> <span class="o">===</span> <span class="s1">&#39;object&#39;</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">&#182;</a> </div> <p>If the value is an <code>Object</code> (and not an <code>Array</code>) then
nest into the value and set the child keys appropriately.
This is done for efficient lookup when setting Object keys.
(i.e. If you set and Object then wish to later retrieve only a
member of that Object, the entire Object need not be retrieved). </p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">self</span><span class="p">.</span><span class="nx">cache</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">value</span><span class="p">);</span>
<span class="nx">self</span><span class="p">.</span><span class="nx">_setObject</span><span class="p">(</span><span class="nx">fullKey</span><span class="p">,</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">callback</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">&#182;</a> </div> <p>If the value is a simple literal (or an <code>Array</code>) then JSON
stringify it and put it into Redis.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">self</span><span class="p">.</span><span class="nx">cache</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">value</span><span class="p">);</span>
<span class="nx">value</span> <span class="o">=</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="nx">value</span><span class="p">);</span>
<span class="nx">self</span><span class="p">.</span><span class="nx">redis</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">fullKey</span><span class="p">,</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">callback</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">});</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#182;</a> </div> <h3>function merge (key, value, callback)</h3>
<h4>@key {string} Key to merge the value into</h4>
<h4>@value {literal|Object} Value to merge into the key</h4>
<h4>2callback {function} Continuation to respond to when complete.</h4>
<p>Merges the properties in <code>value</code> into the existing object value
at <code>key</code>. If the existing value <code>key</code> is not an Object, it will be
completely overwritten.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Redis</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">merge</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">&#182;</a> </div> <p>If the key is not an <code>Object</code> or is an <code>Array</code>,
then simply set it. Merging is for Objects.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">value</span> <span class="o">!==</span> <span class="s1">&#39;object&#39;</span> <span class="o">||</span> <span class="nb">Array</span><span class="p">.</span><span class="nx">isArray</span><span class="p">(</span><span class="nx">value</span><span class="p">))</span> <span class="p">{</span>
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">callback</span><span class="p">);</span>
<span class="p">}</span>
<span class="kd">var</span> <span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">,</span>
<span class="nx">path</span> <span class="o">=</span> <span class="nx">nconf</span><span class="p">.</span><span class="nx">path</span><span class="p">(</span><span class="nx">key</span><span class="p">),</span>
<span class="nx">fullKey</span> <span class="o">=</span> <span class="nx">nconf</span><span class="p">.</span><span class="nx">key</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">namespace</span><span class="p">,</span> <span class="nx">key</span><span class="p">);</span>
</pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">&#182;</a> </div> <p>Set the callback if not provided for "fire and forget"</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">callback</span> <span class="o">=</span> <span class="nx">callback</span> <span class="o">||</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> <span class="p">};</span>
</pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-17">&#182;</a> </div> <p>Get the set of all children keys for the <code>key</code> supplied. If the value
to be returned is an Object, this list will not be empty.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">_addKeys</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">self</span><span class="p">.</span><span class="nx">redis</span><span class="p">.</span><span class="nx">smembers</span><span class="p">(</span><span class="nx">nconf</span><span class="p">.</span><span class="nx">key</span><span class="p">(</span><span class="nx">fullKey</span><span class="p">,</span> <span class="s1">&#39;keys&#39;</span><span class="p">),</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">keys</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">function</span> <span class="nx">nextMerge</span> <span class="p">(</span><span class="nx">nested</span><span class="p">,</span> <span class="nx">next</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">keyPath</span> <span class="o">=</span> <span class="nx">nconf</span><span class="p">.</span><span class="nx">key</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="nx">path</span><span class="p">.</span><span class="nx">concat</span><span class="p">([</span><span class="nx">nested</span><span class="p">]));</span>
<span class="nx">self</span><span class="p">.</span><span class="nx">merge</span><span class="p">(</span><span class="nx">keyPath</span><span class="p">,</span> <span class="nx">value</span><span class="p">[</span><span class="nx">nested</span><span class="p">],</span> <span class="nx">next</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">keys</span> <span class="o">&amp;&amp;</span> <span class="nx">keys</span><span class="p">.</span><span class="nx">length</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-18"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-18">&#182;</a> </div> <p>If there are existing keys then we must do a recursive merge
of the two Objects.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">return</span> <span class="nx">async</span><span class="p">.</span><span class="nx">forEach</span><span class="p">(</span><span class="nb">Object</span><span class="p">.</span><span class="nx">keys</span><span class="p">(</span><span class="nx">value</span><span class="p">),</span> <span class="nx">nextMerge</span><span class="p">,</span> <span class="nx">callback</span><span class="p">);</span>
<span class="p">}</span></pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-19">&#182;</a> </div> <p>Otherwise, we can simply invoke <code>set</code> to override the current
literal or Array value with our new Object value</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">self</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">callback</span><span class="p">);</span>
<span class="p">});</span>
<span class="p">});</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-20"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-20">&#182;</a> </div> <h3>function clear (key, callback)</h3>
<h4>@key {string} Key to remove from this instance</h4>
<h4>@callback {function} Continuation to respond to when complete.</h4>
<p>Removes the value for the specified <code>key</code> from this instance.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Redis</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">clear</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">,</span>
<span class="nx">result</span> <span class="o">=</span> <span class="p">{},</span>
<span class="nx">path</span> <span class="o">=</span> <span class="p">[</span><span class="k">this</span><span class="p">.</span><span class="nx">namespace</span><span class="p">].</span><span class="nx">concat</span><span class="p">(</span><span class="nx">nconf</span><span class="p">.</span><span class="nx">path</span><span class="p">(</span><span class="nx">key</span><span class="p">)),</span>
<span class="nx">last</span> <span class="o">=</span> <span class="nx">path</span><span class="p">.</span><span class="nx">pop</span><span class="p">(),</span>
<span class="nx">fullKey</span> <span class="o">=</span> <span class="nx">nconf</span><span class="p">.</span><span class="nx">key</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">namespace</span><span class="p">,</span> <span class="nx">key</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-21"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-21">&#182;</a> </div> <p>Set the callback if not provided for "fire and forget"</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">callback</span> <span class="o">=</span> <span class="nx">callback</span> <span class="o">||</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> <span class="p">};</span></pre></div> </td> </tr> <tr id="section-22"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-22">&#182;</a> </div> <p>Clear the key from the cache for this instance</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">cache</span><span class="p">.</span><span class="nx">clear</span><span class="p">(</span><span class="nx">key</span><span class="p">);</span>
</pre></div> </td> </tr> <tr id="section-23"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-23">&#182;</a> </div> <p>Remove the <code>key</code> from the parent set of keys.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">redis</span><span class="p">.</span><span class="nx">srem</span><span class="p">(</span><span class="nx">nconf</span><span class="p">.</span><span class="nx">key</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="nx">path</span><span class="p">.</span><span class="nx">concat</span><span class="p">([</span><span class="s1">&#39;keys&#39;</span><span class="p">])),</span> <span class="nx">last</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-24"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-24">&#182;</a> </div> <p>Remove the value from redis by iterating over the set of keys (if any)
and deleting each value. If no keys, then just delete the simple literal.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">self</span><span class="p">.</span><span class="nx">redis</span><span class="p">.</span><span class="nx">smembers</span><span class="p">(</span><span class="nx">nconf</span><span class="p">.</span><span class="nx">key</span><span class="p">(</span><span class="nx">fullKey</span><span class="p">,</span> <span class="s1">&#39;keys&#39;</span><span class="p">),</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">keys</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">function</span> <span class="nx">removeValue</span> <span class="p">(</span><span class="nx">child</span><span class="p">,</span> <span class="nx">next</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-25"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-25">&#182;</a> </div> <p>Recursively call <code>self.clear</code> here to ensure we remove any
nested Objects completely from this instance.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">self</span><span class="p">.</span><span class="nx">clear</span><span class="p">(</span><span class="nx">nconf</span><span class="p">.</span><span class="nx">key</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">child</span><span class="p">),</span> <span class="nx">next</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">keys</span> <span class="o">&amp;&amp;</span> <span class="nx">keys</span><span class="p">.</span><span class="nx">length</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-26"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-26">&#182;</a> </div> <p>If there are child keys then iterate over them,
removing each child along the way.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">async</span><span class="p">.</span><span class="nx">forEach</span><span class="p">(</span><span class="nx">keys</span><span class="p">,</span> <span class="nx">removeValue</span><span class="p">,</span> <span class="nx">callback</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-27"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-27">&#182;</a> </div> <p>Otherwise if this is just a simple literal, then
simply remove it from Redis directly.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">self</span><span class="p">.</span><span class="nx">redis</span><span class="p">.</span><span class="nx">del</span><span class="p">(</span><span class="nx">fullKey</span><span class="p">,</span> <span class="nx">callback</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">});</span>
<span class="p">});</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-28"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-28">&#182;</a> </div> <h3>function save (value, callback)</h3>
<h4>@value {Object} Config object to set for this instance</h4>
<h4>@callback {function} Continuation to respond to when complete.</h4>
<p>Removes any existing configuration settings that may exist in this
instance and then adds all key-value pairs in <code>value</code>. </p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Redis</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">save</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">value</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nb">Array</span><span class="p">.</span><span class="nx">isArray</span><span class="p">(</span><span class="nx">value</span><span class="p">)</span> <span class="o">||</span> <span class="k">typeof</span> <span class="nx">value</span> <span class="o">!==</span> <span class="s1">&#39;object&#39;</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">callback</span><span class="p">(</span><span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s1">&#39;`value` to be saved must be an object.&#39;</span><span class="p">));</span>
<span class="p">}</span>
<span class="kd">var</span> <span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">,</span>
<span class="nx">keys</span> <span class="o">=</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">keys</span><span class="p">(</span><span class="nx">value</span><span class="p">);</span>
</pre></div> </td> </tr> <tr id="section-29"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-29">&#182;</a> </div> <p>Set the callback if not provided for "fire and forget"</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">callback</span> <span class="o">=</span> <span class="nx">callback</span> <span class="o">||</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> <span class="p">};</span></pre></div> </td> </tr> <tr id="section-30"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-30">&#182;</a> </div> <p>Clear all existing keys associated with this instance.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">reset</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">err</span><span class="p">);</span>
<span class="p">}</span>
</pre></div> </td> </tr> <tr id="section-31"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-31">&#182;</a> </div> <p>Iterate over the keys in the new value, setting each of them.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">async</span><span class="p">.</span><span class="nx">forEach</span><span class="p">(</span><span class="nx">keys</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">next</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">self</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">value</span><span class="p">[</span><span class="nx">key</span><span class="p">],</span> <span class="nx">next</span><span class="p">);</span>
<span class="p">},</span> <span class="nx">callback</span><span class="p">);</span>
<span class="p">});</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-32"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-32">&#182;</a> </div> <h3>function load (callback)</h3>
<h4>@callback {function} Continuation to respond to when complete.</h4>
<p>Responds with an Object representing all keys associated in this instance.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Redis</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">load</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">,</span>
<span class="nx">result</span> <span class="o">=</span> <span class="p">{};</span>
</pre></div> </td> </tr> <tr id="section-33"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-33">&#182;</a> </div> <p>Set the callback if not provided for "fire and forget"</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">callback</span> <span class="o">=</span> <span class="nx">callback</span> <span class="o">||</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> <span class="p">};</span>
<span class="k">this</span><span class="p">.</span><span class="nx">redis</span><span class="p">.</span><span class="nx">smembers</span><span class="p">(</span><span class="nx">nconf</span><span class="p">.</span><span class="nx">key</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">namespace</span><span class="p">,</span> <span class="s1">&#39;keys&#39;</span><span class="p">),</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">keys</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">err</span><span class="p">);</span>
<span class="p">}</span>
<span class="kd">function</span> <span class="nx">addValue</span> <span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">next</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">self</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">value</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">next</span><span class="p">(</span><span class="nx">err</span><span class="p">);</span>
<span class="p">}</span>
<span class="nx">result</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="nx">value</span><span class="p">;</span>
<span class="nx">next</span><span class="p">();</span>
<span class="p">});</span>
<span class="p">}</span>
<span class="nx">keys</span> <span class="o">=</span> <span class="nx">keys</span> <span class="o">||</span> <span class="p">[];</span>
<span class="nx">async</span><span class="p">.</span><span class="nx">forEach</span><span class="p">(</span><span class="nx">keys</span><span class="p">,</span> <span class="nx">addValue</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">err</span> <span class="o">?</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="o">:</span> <span class="nx">callback</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="nx">result</span><span class="p">);</span>
<span class="p">});</span>
<span class="p">});</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-34"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-34">&#182;</a> </div> <h3>function reset (callback)</h3>
<h4>@callback {function} Continuation to respond to when complete.</h4>
<p>Clears all keys associated with this instance.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Redis</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">reset</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span>
</pre></div> </td> </tr> <tr id="section-35"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-35">&#182;</a> </div> <p>Set the callback if not provided for "fire and forget"</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">callback</span> <span class="o">=</span> <span class="nx">callback</span> <span class="o">||</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> <span class="p">};</span>
</pre></div> </td> </tr> <tr id="section-36"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-36">&#182;</a> </div> <p>Get the list of of top-level keys, then clear each of them</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">this</span><span class="p">.</span><span class="nx">redis</span><span class="p">.</span><span class="nx">smembers</span><span class="p">(</span><span class="nx">nconf</span><span class="p">.</span><span class="nx">key</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">namespace</span><span class="p">,</span> <span class="s1">&#39;keys&#39;</span><span class="p">),</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">existing</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">err</span><span class="p">);</span>
<span class="p">}</span>
<span class="nx">existing</span> <span class="o">=</span> <span class="nx">existing</span> <span class="o">||</span> <span class="p">[];</span>
<span class="nx">async</span><span class="p">.</span><span class="nx">forEach</span><span class="p">(</span><span class="nx">existing</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">next</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">self</span><span class="p">.</span><span class="nx">clear</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">next</span><span class="p">);</span>
<span class="p">},</span> <span class="nx">callback</span><span class="p">);</span>
<span class="p">});</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-37"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-37">&#182;</a> </div> <h3>@private function _addKeys (key, callback)</h3>
<h4>@key {string} Key to add parent keys for</h4>
<h4>@callback {function} Continuation to respond to when complete.</h4>
<p>Adds the full <code>key</code> path to Redis via <code>sadd</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Redis</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">_addKeys</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">,</span>
<span class="nx">path</span> <span class="o">=</span> <span class="nx">nconf</span><span class="p">.</span><span class="nx">path</span><span class="p">(</span><span class="nx">key</span><span class="p">);</span>
<span class="kd">function</span> <span class="nx">addKey</span> <span class="p">(</span><span class="nx">partial</span><span class="p">,</span> <span class="nx">next</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">index</span> <span class="o">=</span> <span class="nx">path</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="nx">partial</span><span class="p">),</span>
<span class="nx">base</span> <span class="o">=</span> <span class="p">[</span><span class="nx">self</span><span class="p">.</span><span class="nx">namespace</span><span class="p">].</span><span class="nx">concat</span><span class="p">(</span><span class="nx">path</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nx">index</span><span class="p">)),</span>
<span class="nx">parent</span> <span class="o">=</span> <span class="nx">nconf</span><span class="p">.</span><span class="nx">key</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="nx">base</span><span class="p">.</span><span class="nx">concat</span><span class="p">([</span><span class="s1">&#39;keys&#39;</span><span class="p">]));</span>
<span class="nx">self</span><span class="p">.</span><span class="nx">redis</span><span class="p">.</span><span class="nx">sadd</span><span class="p">(</span><span class="nx">parent</span><span class="p">,</span> <span class="nx">partial</span><span class="p">,</span> <span class="nx">next</span><span class="p">);</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-38"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-38">&#182;</a> </div> <p>Iterate over the entire key path and add each key to the
parent key-set if it doesn't exist already.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">async</span><span class="p">.</span><span class="nx">forEach</span><span class="p">(</span><span class="nx">path</span><span class="p">,</span> <span class="nx">addKey</span><span class="p">,</span> <span class="nx">callback</span><span class="p">);</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-39"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-39">&#182;</a> </div> <h3>@private function _setObject (key, value, callback)</h3>
<h4>@key {string} Key to set in this instance</h4>
<h4>@value {Object} Value for the specified key</h4>
<h4>@callback {function} Continuation to respond to when complete.</h4>
<p>Internal helper function for setting all keys of a nested object.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Redis</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">_setObject</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">callback</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">,</span>
<span class="nx">keys</span> <span class="o">=</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">keys</span><span class="p">(</span><span class="nx">value</span><span class="p">);</span>
<span class="kd">function</span> <span class="nx">addValue</span> <span class="p">(</span><span class="nx">child</span><span class="p">,</span> <span class="nx">next</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-40"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-40">&#182;</a> </div> <p>Add the child key to the parent key-set, then set the value.
Recursively call <code>_setObject</code> in the event of nested Object(s).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">self</span><span class="p">.</span><span class="nx">redis</span><span class="p">.</span><span class="nx">sadd</span><span class="p">(</span><span class="nx">nconf</span><span class="p">.</span><span class="nx">key</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="s1">&#39;keys&#39;</span><span class="p">),</span> <span class="nx">child</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">next</span><span class="p">(</span><span class="nx">err</span><span class="p">);</span>
<span class="p">}</span>
<span class="kd">var</span> <span class="nx">fullKey</span> <span class="o">=</span> <span class="nx">nconf</span><span class="p">.</span><span class="nx">key</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">child</span><span class="p">),</span>
<span class="nx">childValue</span> <span class="o">=</span> <span class="nx">value</span><span class="p">[</span><span class="nx">child</span><span class="p">];</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nb">Array</span><span class="p">.</span><span class="nx">isArray</span><span class="p">(</span><span class="nx">childValue</span><span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="k">typeof</span> <span class="nx">childValue</span> <span class="o">===</span> <span class="s1">&#39;object&#39;</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">self</span><span class="p">.</span><span class="nx">_setObject</span><span class="p">(</span><span class="nx">fullKey</span><span class="p">,</span> <span class="nx">childValue</span><span class="p">,</span> <span class="nx">next</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">else</span> <span class="p">{</span>
<span class="nx">childValue</span> <span class="o">=</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="nx">childValue</span><span class="p">);</span>
<span class="nx">self</span><span class="p">.</span><span class="nx">redis</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">fullKey</span><span class="p">,</span> <span class="nx">childValue</span><span class="p">,</span> <span class="nx">next</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">});</span>
<span class="p">}</span>
</pre></div> </td> </tr> <tr id="section-41"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-41">&#182;</a> </div> <p>Iterate over the keys of the Object and set the appropriate values.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">async</span><span class="p">.</span><span class="nx">forEach</span><span class="p">(</span><span class="nx">keys</span><span class="p">,</span> <span class="nx">addValue</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">err</span> <span class="o">?</span> <span class="nx">callback</span><span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="o">:</span> <span class="nx">callback</span><span class="p">();</span>
<span class="p">});</span>
<span class="p">};</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>

View file

@ -0,0 +1,98 @@
<!DOCTYPE html> <html> <head> <title>system.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="../../docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="../..//nconf/common.html"> nconf/common.html </a> <a class="source" href="../..//nconf/formats.html"> nconf/formats.html </a> <a class="source" href="../..//nconf/provider.html"> nconf/provider.html </a> <a class="source" href="../..//nconf/stores/file.html"> nconf/stores/file.html </a> <a class="source" href="../..//nconf/stores/memory.html"> nconf/stores/memory.html </a> <a class="source" href="../..//nconf/stores/system.html"> nconf/stores/system.html </a> <a class="source" href="../..//nconf/stores.html"> nconf/stores.html </a> <a class="source" href="../..//nconf.html"> nconf.html </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> system.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
<span class="cm"> * system.js: Simple memory-based store for process environment variables and</span>
<span class="cm"> * command-line arguments.</span>
<span class="cm"> *</span>
<span class="cm"> * (C) 2011, Charlie Robbins</span>
<span class="cm"> *</span>
<span class="cm"> */</span>
<span class="kd">var</span> <span class="nx">util</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;util&#39;</span><span class="p">),</span>
<span class="nx">Memory</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./memory&#39;</span><span class="p">).</span><span class="nx">Memory</span><span class="p">;</span>
</pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <h3>function System (options)</h3>
<h4>@options {Object} Options for this instance.</h4>
<p>Constructor function for the System nconf store, a simple abstraction
around the Memory store that can read process environment variables
and command-line arguments.</p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">System</span> <span class="o">=</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">System</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">options</span> <span class="o">=</span> <span class="nx">options</span> <span class="o">||</span> <span class="p">{};</span>
<span class="nx">Memory</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">options</span><span class="p">);</span>
<span class="k">this</span><span class="p">.</span><span class="nx">type</span> <span class="o">=</span> <span class="s1">&#39;system&#39;</span><span class="p">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">overrides</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">overrides</span> <span class="o">||</span> <span class="kc">null</span><span class="p">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">env</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">env</span> <span class="o">||</span> <span class="kc">false</span><span class="p">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">argv</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">argv</span> <span class="o">||</span> <span class="kc">false</span><span class="p">;</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Inherit from the Memory store</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">util</span><span class="p">.</span><span class="nx">inherits</span><span class="p">(</span><span class="nx">System</span><span class="p">,</span> <span class="nx">Memory</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <h3>function loadSync ()</h3>
<p>Loads the data passed in from <code>process.env</code> into this instance.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">System</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">loadSync</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">env</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">loadEnv</span><span class="p">();</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">argv</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">loadArgv</span><span class="p">();</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">overrides</span><span class="p">)</span> <span class="p">{</span>
<span class="k">this</span><span class="p">.</span><span class="nx">loadOverrides</span><span class="p">();</span>
<span class="p">}</span>
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">store</span><span class="p">;</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <h3>function loadOverrides ()</h3>
<p>Loads any overrides set on this instance into
the underlying managed <code>Memory</code> store.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">System</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">loadOverrides</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="k">this</span><span class="p">.</span><span class="nx">overrides</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
<span class="kd">var</span> <span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">,</span>
<span class="nx">keys</span> <span class="o">=</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">keys</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">overrides</span><span class="p">);</span>
<span class="nx">keys</span><span class="p">.</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">self</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">self</span><span class="p">.</span><span class="nx">overrides</span><span class="p">[</span><span class="nx">key</span><span class="p">]);</span>
<span class="p">});</span>
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">store</span><span class="p">;</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <h3>function loadArgv ()</h3>
<p>Loads the data passed in from the command-line arguments
into this instance.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">System</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">loadArgv</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">,</span>
<span class="nx">argv</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="k">this</span><span class="p">.</span><span class="nx">argv</span> <span class="o">===</span> <span class="s1">&#39;object&#39;</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">argv</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;optimist&#39;</span><span class="p">).</span><span class="nx">options</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">argv</span><span class="p">).</span><span class="nx">argv</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">argv</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">argv</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;optimist&#39;</span><span class="p">).</span><span class="nx">argv</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">argv</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
<span class="nb">Object</span><span class="p">.</span><span class="nx">keys</span><span class="p">(</span><span class="nx">argv</span><span class="p">).</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">self</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">argv</span><span class="p">[</span><span class="nx">key</span><span class="p">]);</span>
<span class="p">});</span>
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">store</span><span class="p">;</span>
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <h3>function loadEnv ()</h3>
<p>Loads the data passed in from <code>process.env</code> into this instance.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">System</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">loadEnv</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="k">this</span><span class="p">.</span><span class="nx">env</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
<span class="nb">Object</span><span class="p">.</span><span class="nx">keys</span><span class="p">(</span><span class="nx">process</span><span class="p">.</span><span class="nx">env</span><span class="p">).</span><span class="nx">filter</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="o">!</span><span class="nx">self</span><span class="p">.</span><span class="nx">env</span><span class="p">.</span><span class="nx">length</span> <span class="o">||</span> <span class="nx">self</span><span class="p">.</span><span class="nx">env</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="nx">key</span><span class="p">)</span> <span class="o">!==</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>
<span class="p">}).</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">self</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">process</span><span class="p">.</span><span class="nx">env</span><span class="p">[</span><span class="nx">key</span><span class="p">]);</span>
<span class="p">});</span>
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">store</span><span class="p">;</span>
<span class="p">};</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>