summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2019-06-12 17:40:20 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2020-02-14 10:47:58 -0800
commitfc25d304203409093206ab2a76698932b990641c (patch)
tree761b10abd834515826eb516c82ce71cbd924571f
parent361edd250687dbe93587a659c1fc93baf35be000 (diff)
downloadchef-lcg/yml-recipes.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>
-rw-r--r--lib/chef/mixin/from_file.rb17
-rw-r--r--lib/chef/recipe.rb21
2 files changed, 21 insertions, 17 deletions
diff --git a/lib/chef/mixin/from_file.rb b/lib/chef/mixin/from_file.rb
index 94e3144f9f..b8300340c7 100644
--- a/lib/chef/mixin/from_file.rb
+++ b/lib/chef/mixin/from_file.rb
@@ -37,23 +37,6 @@ class Chef
end
end
- # This will return an array of hashes or something that then needs to get inflated.
- def from_yaml_file(filename)
- self.source_file = filename
- if File.file?(filename) && File.readable?(filename)
- res = ::YAML.safe_load(IO.read(filename))
- if res.is_a?(Hash)
- from_hash(res)
- elsif res.is_a?(Array)
- from_array(res)
- else
- raise "boom"
- end
- else
- raise IOError, "Cannot open or read #{filename}!"
- end
- end
-
# Loads a given ruby file, and runs class_eval against it in the context of the current
# object.
#
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