Sure, you can inspect the run_context
. This is how ChefSpec does it:
#
# Automatically appends "+::default+" to recipes that need them.
#
# @param [String] name
#
# @return [String]
#
def with_default(name)
name.include?('::') ? name : "#{name}::default"
end
#
# The list of loaded recipes on the Chef run (normalized)
#
# @return [Array<String>]
#
def loaded_recipes
@runner.run_context.loaded_recipes.map { |name| with_default(name) }
end
So that answers your question. Now my question - why?
Chef will automatically build up the dependency graph for you. It will only include the recipe once, at the appropriate place of order. You don't need to manually manage this graph, and it is "okay" to include the same recipe more than once.
In fact, internally, we use this pattern quite frequently. Each recipe declares the recipes it depends on at the very top. I'd recommend watching this video: https://www.youtube.com/watch?v=hYt0E84kYUI