Skip to content

Commit

Permalink
Prioritise dependent reps
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdefreyne committed Jan 29, 2017
1 parent ac9e568 commit 4531cbf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/nanoc/base/services/item_rep_selector.rb
Expand Up @@ -14,7 +14,7 @@ def each

prioritised = Set.new
loop do
rep = next(graph, prioritised)
rep = find(graph, prioritised)
break if NONE.equal?(rep)

begin
Expand All @@ -31,9 +31,20 @@ def each
end
end

def next(graph, _prioritised)
def find(graph, prioritised)
if graph.roots.empty?
NONE
elsif prioritised.any?
until prioritised.empty?
rep = prioritised.each { |e| break e }
if graph.roots.include?(rep)
return rep
else
prioritised.delete(rep)
end
end

find(graph, prioritised)
else
graph.roots.each { |e| break e }
end
Expand Down
15 changes: 15 additions & 0 deletions spec/nanoc/base/services/item_rep_selector_spec.rb
Expand Up @@ -165,5 +165,20 @@
expect(tentatively_yielded).to eq [:a, :b, :a, :c, :a, :d, :a, :e, :a]
end
end

context 'unrelated roots' do
let(:dependencies) do
{
a: [:d],
b: [:e],
c: [],
}
end

it 'picks prioritised roots' do
expect(successfully_yielded).to eq [:d, :e, :c, :a, :b]
expect(tentatively_yielded).to eq [:a, :d, :b, :e, :c, :a, :b]
end
end
end
end

0 comments on commit 4531cbf

Please sign in to comment.