diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2019-06-12 17:40:20 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2020-02-14 10:47:58 -0800 |
commit | fc25d304203409093206ab2a76698932b990641c (patch) | |
tree | 761b10abd834515826eb516c82ce71cbd924571f /lib/chef/recipe.rb | |
parent | 361edd250687dbe93587a659c1fc93baf35be000 (diff) | |
download | chef-fc25d304203409093206ab2a76698932b990641c.tar.gz |
code rearrangement and warn about using arrayslcg/yml-recipes
from_yaml_file was not actually generic i don't think
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef/recipe.rb')
-rw-r--r-- | lib/chef/recipe.rb | 21 |
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 |