summaryrefslogtreecommitdiff
path: root/lib/chef/run_context.rb
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2012-11-30 14:43:58 -0800
committerdanielsdeleo <dan@opscode.com>2012-11-30 14:51:48 -0800
commit260a3348cf592f513eaf156719976e6c4541b2fe (patch)
treeddfa56f58336db2244f3a71b1c4d4bc375c33f96 /lib/chef/run_context.rb
parentcad1d6ad7fe7940f496961c7edbd35272d3c973e (diff)
downloadchef-260a3348cf592f513eaf156719976e6c4541b2fe.tar.gz
[CHEF-3376] expose loaded recipes as an array
`loaded_recipes` is a Hash-based set internally, but only the keys are actually useful.
Diffstat (limited to 'lib/chef/run_context.rb')
-rw-r--r--lib/chef/run_context.rb33
1 files changed, 23 insertions, 10 deletions
diff --git a/lib/chef/run_context.rb b/lib/chef/run_context.rb
index 542b1ea169..6477431967 100644
--- a/lib/chef/run_context.rb
+++ b/lib/chef/run_context.rb
@@ -60,16 +60,6 @@ class Chef
# Event dispatcher for this run.
attr_reader :events
- # A Hash used as a set containing the names of the recipes that have
- # already been evaluated. Instead of accessing this directly, you should
- # use #loaded_recipe? to determine if a recipe has been loaded.
- attr_reader :loaded_recipes
-
- # A Hash used as a set containing the names of the attributes files that
- # have been evaluated. Instead of accessing this directly, you should use
- # #loaded_attribute? to determine if an attribute file has been loaded.
- attr_reader :loaded_attributes
-
# Creates a new Chef::RunContext object and populates its fields. This object gets
# used by the Chef Server to generate a fully compiled recipe list for a node.
#
@@ -174,10 +164,33 @@ class Chef
attribute_filename
end
+ # An Array of all recipes that have been loaded. This is stored internally
+ # as a Hash, so ordering is not preserved when using ruby 1.8.
+ #
+ # Recipe names are given in fully qualified form, e.g., the recipe "nginx"
+ # will be given as "nginx::default"
+ #
+ # To determine if a particular recipe has been loaded, use #loaded_recipe?
+ def loaded_recipes
+ @loaded_recipes.keys
+ end
+
+ # An Array of all attributes files that have been loaded. Stored internally
+ # using a Hash, so order is not preserved on ruby 1.8.
+ #
+ # Attribute file names are given in fully qualified form, e.g.,
+ # "nginx::default" instead of "nginx".
+ def loaded_attributes
+ @loaded_attributes.keys
+ end
+
def loaded_fully_qualified_recipe?(cookbook, recipe)
@loaded_recipes.has_key?("#{cookbook}::#{recipe}")
end
+ # Returns true if +recipe+ has been loaded, false otherwise. Default recipe
+ # names are expanded, so `loaded_recipe?("nginx")` and
+ # `loaded_recipe?("nginx::default")` are valid and give identical results.
def loaded_recipe?(recipe)
cookbook, recipe_name = Chef::Recipe.parse_recipe_name(recipe)
loaded_fully_qualified_recipe?(cookbook, recipe_name)