Permalink
Browse files

Added helper function to ArcList for returning a NodeList of the from…

… or to property. Cleans up a few scenarios.
  • Loading branch information...
1 parent 238c196 commit ce7155058c4362dc8a1a3e6bf2c7ef49089d459f @KrisJordan committed Jan 4, 2011
Showing with 19 additions and 7 deletions.
  1. +8 −2 docs/dag.html
  2. +1 −1 docs/rules.html
  3. +9 −3 src/dag.coffee
  4. +1 −1 src/rules.coffee
View
@@ -147,9 +147,15 @@
<span class="k">class</span> <span class="nx">ArcList</span> <span class="k">extends</span> <span class="nx">List</span>
<span class="nv">from: </span><span class="nf">(node) -&gt;</span>
- <span class="k">new</span> <span class="nx">ArcList</span> <span class="nx">_</span><span class="p">(</span><span class="nx">@items</span><span class="p">).</span><span class="nx">filter</span> <span class="nf">(arc) -&gt;</span> <span class="nx">arc</span><span class="p">.</span><span class="nx">from</span> <span class="o">==</span> <span class="nx">node</span>
+ <span class="k">if</span> <span class="nx">node</span><span class="o">?</span>
+ <span class="k">new</span> <span class="nx">ArcList</span> <span class="nx">_</span><span class="p">(</span><span class="nx">@items</span><span class="p">).</span><span class="nx">filter</span> <span class="nf">(arc) -&gt;</span> <span class="nx">arc</span><span class="p">.</span><span class="nx">from</span> <span class="o">==</span> <span class="nx">node</span>
+ <span class="k">else</span>
+ <span class="k">new</span> <span class="nx">NodeList</span> <span class="k">this</span><span class="p">.</span><span class="nx">pluckUniq</span> <span class="s1">&#39;from&#39;</span>
<span class="nv">to: </span><span class="nf">(node) -&gt;</span>
- <span class="k">new</span> <span class="nx">ArcList</span> <span class="nx">_</span><span class="p">(</span><span class="nx">@items</span><span class="p">).</span><span class="nx">filter</span> <span class="nf">(arc) -&gt;</span> <span class="nx">arc</span><span class="p">.</span><span class="nx">to</span> <span class="o">==</span> <span class="nx">node</span>
+ <span class="k">if</span> <span class="nx">node</span><span class="o">?</span>
+ <span class="k">new</span> <span class="nx">ArcList</span> <span class="nx">_</span><span class="p">(</span><span class="nx">@items</span><span class="p">).</span><span class="nx">filter</span> <span class="nf">(arc) -&gt;</span> <span class="nx">arc</span><span class="p">.</span><span class="nx">to</span> <span class="o">==</span> <span class="nx">node</span>
+ <span class="k">else</span>
+ <span class="k">new</span> <span class="nx">NodeList</span> <span class="k">this</span><span class="p">.</span><span class="nx">pluckUniq</span> <span class="s1">&#39;to&#39;</span>
<span class="nv">pluckUniq: </span><span class="nf">(property) -&gt;</span>
<span class="nx">_</span><span class="p">(</span><span class="nx">@items</span><span class="p">).</span><span class="nx">chain</span><span class="p">().</span><span class="nx">pluck</span><span class="p">(</span><span class="nx">property</span><span class="p">).</span><span class="nx">uniq</span><span class="p">().</span><span class="nx">value</span><span class="p">()</span>
<span class="nv">clone: </span><span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">ArcList</span> <span class="k">super</span><span class="p">().</span><span class="nx">items</span></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-17">&#182;</a> </div> <h3>Exports</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nx">_</span><span class="p">(</span><span class="nx">exports</span><span class="p">).</span><span class="nx">extend</span> <span class="p">{</span><span class="nx">Node</span><span class="p">,</span><span class="nx">Arc</span><span class="p">,</span><span class="nx">List</span><span class="p">,</span><span class="nx">NodeList</span><span class="p">,</span><span class="nx">ArcList</span><span class="p">,</span><span class="nx">Graph</span><span class="p">}</span>
View
@@ -37,7 +37,7 @@
other RecipeNode targets have a RecipeNode with outputs as a prereq
its dependency is on those FileNode outputs and not the RecipeNode
itself.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="nx">input</span> <span class="k">instanceof</span> <span class="nx">RecipeNode</span>
- <span class="nv">inputsOutputs = </span><span class="p">(</span><span class="k">new</span> <span class="nx">NodeList</span> <span class="nx">graph</span><span class="p">.</span><span class="nx">arcs</span><span class="p">.</span><span class="nx">from</span><span class="p">(</span><span class="nx">input</span><span class="p">).</span><span class="nx">pluck</span><span class="p">(</span><span class="s1">&#39;to&#39;</span><span class="p">)).</span><span class="nx">ofType</span><span class="p">(</span><span class="nx">FileNode</span><span class="p">)</span>
+ <span class="nv">inputsOutputs = </span> <span class="nx">graph</span><span class="p">.</span><span class="nx">arcs</span><span class="p">.</span><span class="nx">from</span><span class="p">(</span><span class="nx">input</span><span class="p">).</span><span class="nx">to</span><span class="p">().</span><span class="nx">ofType</span><span class="p">(</span><span class="nx">FileNode</span><span class="p">)</span>
<span class="k">if</span> <span class="o">not</span> <span class="nx">inputsOutputs</span><span class="p">.</span><span class="nx">isEmpty</span><span class="p">()</span>
<span class="nx">inputsOutputs</span><span class="p">.</span><span class="nx">forEach</span> <span class="nf">(inputsOutput) -&gt;</span>
<span class="nx">graph</span><span class="p">.</span><span class="nx">arc</span> <span class="nx">inputsOutput</span><span class="p">.</span><span class="nx">name</span><span class="p">,</span> <span class="nx">target</span><span class="p">.</span><span class="nx">name</span>
View
@@ -87,7 +87,7 @@ class Graph
# list of all nodes.
sources: -> # NodeList
nodesWithoutInboundArcs = do @nodes.clone
- _(@arcs.pluckUniq 'to').forEach (node) ->
+ @arcs.to().forEach (node) ->
nodesWithoutInboundArcs.remove node
nodesWithoutInboundArcs
@@ -189,9 +189,15 @@ class NodeList extends List
class ArcList extends List
from: (node) ->
- new ArcList _(@items).filter (arc) -> arc.from == node
+ if node?
+ new ArcList _(@items).filter (arc) -> arc.from == node
+ else
+ new NodeList this.pluckUniq 'from'
to: (node) ->
- new ArcList _(@items).filter (arc) -> arc.to == node
+ if node?
+ new ArcList _(@items).filter (arc) -> arc.to == node
+ else
+ new NodeList this.pluckUniq 'to'
pluckUniq: (property) ->
_(@items).chain().pluck(property).uniq().value()
clone: -> new ArcList super().items
View
@@ -42,7 +42,7 @@ class RuleGraph extends Graph
# its dependency is on those FileNode outputs and not the RecipeNode
# itself.
if input instanceof RecipeNode
- inputsOutputs = (new NodeList graph.arcs.from(input).pluck('to')).ofType(FileNode)
+ inputsOutputs = graph.arcs.from(input).to().ofType(FileNode)
if not inputsOutputs.isEmpty()
inputsOutputs.forEach (inputsOutput) ->
graph.arc inputsOutput.name, target.name

0 comments on commit ce71550

Please sign in to comment.