lib/jsus/container.rb in jsus-0.3.4 vs lib/jsus/container.rb in jsus-0.3.5
- old
+ new
@@ -126,28 +126,35 @@
dependency_cache[dependency].each do |required_item|
graph.add_edge(required_item, item)
end
end
end
- result = []
- if Jsus.look_for_cycles?
- cycles = graph.cycles
- error_msg = []
- unless cycles.empty?
- error_msg << "Jsus has discovered you have circular dependencies in your code."
- error_msg << "Please resolve them immediately!"
- error_msg << "List of circular dependencies:"
- cycles.each do |cycle|
- error_msg << "-" * 30
- error_msg << (cycle + [cycle.first]).map {|sf| sf.filename}.join(" => ")
- end
- error_msg = error_msg.join("\n")
- Jsus.logger.fatal(error_msg)
- end
+
+ begin
+ graph.topsorted_vertices
+ rescue RGL::TopsortedGraphHasCycles => e
+ output_cycles(graph)
+ raise e # fail fast
end
- graph.topsort_iterator.each { |item| result << item }
- result
end
+
+ # @api private
+ def output_cycles(graph)
+ cycles = graph.cycles
+ error_msg = []
+ unless cycles.empty?
+ error_msg << "Jsus has discovered you have circular dependencies in your code."
+ error_msg << "Please resolve them immediately!"
+ error_msg << "List of circular dependencies:"
+ cycles.each do |cycle|
+ error_msg << "-" * 30
+ error_msg << (cycle + [cycle.first]).map {|sf| sf.filename}.join(" => ")
+ end
+ error_msg << "-" * 30
+ error_msg = error_msg.join("\n")
+ Jsus.logger.fatal(error_msg)
+ end
+ end # output_cycles
# Cached map of dependencies pointing to source files.
# @return [Hash]
# @api private
def dependency_cache