summaryrefslogtreecommitdiff
path: root/lib/chef/recipe.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef/recipe.rb')
-rw-r--r--lib/chef/recipe.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/chef/recipe.rb b/lib/chef/recipe.rb
index 95b69532f8..ddb45de8e3 100644
--- a/lib/chef/recipe.rb
+++ b/lib/chef/recipe.rb
@@ -85,7 +85,28 @@ class Chef
end
end
+ def from_yaml_file(filename)
+ self.source_file = filename
+ if File.file?(filename) && File.readable?(filename)
+ from_yaml(IO.read(filename))
+ else
+ raise IOError, "Cannot open or read #{filename}!"
+ end
+ end
+
+ def from_yaml(string)
+ res = ::YAML.safe_load(string)
+ if res.is_a?(Hash)
+ from_hash(res)
+ elsif res.is_a?(Array)
+ from_array(res)
+ else
+ raise "boom"
+ end
+ end
+
def from_array(array)
+ Chef::Log.warn "array yaml files are super duper experimental behavior"
array.each { |e| from_hash(e) }
end