Module: Poise::Helpers::IncludeRecipe
Overview
A provider mixin to add #include_recipe that can be called from action methods.
Instance Method Summary collapse
Instance Method Details
#include_recipe(*recipes) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/poise/helpers/include_recipe.rb', line 30 def include_recipe(*recipes) loaded_recipes = [] subcontext = subcontext_block do recipes.each do |recipe| case recipe when String # Process normally Chef::Log.debug("Loading recipe #{recipe} via include_recipe (poise)") loaded_recipes += run_context.include_recipe(recipe) when Proc # Pretend its a block of recipe code fake_recipe = Chef::Recipe.new(cookbook_name, new_resource.recipe_name, run_context) fake_recipe.instance_eval(&recipe) loaded_recipes << fake_recipe end end end # Converge the new context. Poise::Subcontext::Runner.new(new_resource, subcontext).converge collection = global_resource_collection subcontext.resource_collection.each do |r| Chef::Log.debug("Poise::IncludeRecipe: Adding #{r} to global collection #{collection.object_id}") # Insert the local resource into the global context collection.insert(r) # Skip the iterator forward so we don't double-execute the inserted resource # If running at compile time, the iterator is nil collection.iterator.skip_forward if collection.iterator end loaded_recipes end |