Fuel plugin to deploy Sensu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dependency_resolver.rb 555B

123456789101112131415161718192021222324
  1. require 'tsort'
  2. module Dentaku
  3. class DependencyResolver
  4. include TSort
  5. def self.find_resolve_order(vars_to_dependencies_hash)
  6. self.new(vars_to_dependencies_hash).tsort
  7. end
  8. def initialize(vars_to_dependencies_hash)
  9. # ensure variables are strings
  10. @vars_to_deps = Hash[vars_to_dependencies_hash.map { |k, v| [k.to_s, v]}]
  11. end
  12. def tsort_each_node(&block)
  13. @vars_to_deps.each_key(&block)
  14. end
  15. def tsort_each_child(node, &block)
  16. @vars_to_deps.fetch(node.to_s, []).each(&block)
  17. end
  18. end
  19. end