A good tool for dependency resolution is Ruby’s TSort standard library module.
It used to be part of Bundler to resolve dependencies. Bundler now uses the Molinillo Gem instead. However the approach hasn’t really changed, Molinillo still uses TSort under the hood.
TSort implements topological sorting using Tarjan’s algorithm for strongly connected components.
Here are some articles that illustrate how and where it can be used: