Class: Nanoc::Int::ItemRepSelector Private

Inherits:
Object
  • Object
show all
Defined in:
lib/nanoc/base/services/item_rep_selector.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Yields item reps to compile.

Instance Method Summary collapse

Constructor Details

#initialize(reps) ⇒ ItemRepSelector

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ItemRepSelector.



6
7
8
# File 'lib/nanoc/base/services/item_rep_selector.rb', line 6

def initialize(reps)
  @reps = reps
end

Instance Method Details

#eachObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/nanoc/base/services/item_rep_selector.rb', line 10

def each
  graph = Nanoc::Int::DirectedGraph.new(@reps)

  loop do
    break if graph.roots.empty?
    rep = graph.roots.each { |e| break e }

    begin
      yield(rep)
      graph.delete_vertex(rep)
    rescue Nanoc::Int::Errors::UnmetDependency => e
      handle_dependency_error(e, rep, graph)
    end
  end

  # Check whether everything was compiled
  unless graph.vertices.empty?
    raise Nanoc::Int::Errors::RecursiveCompilation.new(graph.vertices)
  end
end

#handle_dependency_error(e, rep, graph) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



31
32
33
34
35
36
37
# File 'lib/nanoc/base/services/item_rep_selector.rb', line 31

def handle_dependency_error(e, rep, graph)
  other_rep = e.rep
  graph.add_edge(other_rep, rep)
  unless graph.vertices.include?(other_rep)
    graph.add_vertex(other_rep)
  end
end