lib/grape/reload/dependency_map.rb in grape-reload-0.0.2 vs lib/grape/reload/dependency_map.rb in grape-reload-0.0.3

- old
+ new

@@ -1,9 +1,14 @@ require_relative '../../ripper/extract_constants' module Grape module Reload + class UnresolvedDependenciesError < RuntimeError + def message; 'One or more unresolved dependencies found' end + end + + class DependencyMap extend Forwardable include TSort attr_accessor :map @@ -30,15 +35,16 @@ map.keys end def dependent_classes(loaded_file) classes = [] + sorted = sorted_files cycle_classes = ->(file, visited_files = []){ return if visited_files.include?(file) visited_files ||= [] visited_files << file - classes |= map[file][:declared] if file != loaded_file + classes |= map[file][:declared] map[file][:declared].map{|klass| file_class = map.each_pair .sort{|a1, a2| sorted.index(a1.first) - sorted.index(a2.first) } @@ -108,9 +114,11 @@ end unresolved_classes.each_pair do |klass, filenames| filenames.each {|filename| Grape::RackBuilder.logger.error("Unresolved const reference #{klass} from: #{filename}".colorize(:red)) } end + + raise UnresolvedDependenciesError if unresolved_classes.any? end end class Sources extend Forwardable \ No newline at end of file