Skip to content

Instantly share code, notes, and snippets.

@atoulme
Created May 21, 2010 04:04
Show Gist options
  • Save atoulme/408446 to your computer and use it in GitHub Desktop.
Save atoulme/408446 to your computer and use it in GitHub Desktop.
# find first callback with satisfied dependencies
def first_satisfied(r, known_callbacks)
remaining_names = r.map { |cb| cb.name }
res = r.find do |cb|
cb.dependencies.each do |dep|
fail "Unknown #{phase.inspect} extension dependency: #{dep.inspect}" unless known_callbacks.index(dep)
end
satisfied = cb.dependencies.find { |dep| remaining_names.index(dep) } == nil
cb if satisfied
end
r.delete res
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment