Please review pull request #32: Differentiate between unique and non-unique array search opened by (Preston4tw)
Description:
A small patch to add an option to allow for non-unique array search by default, and a different unique array search.
Diff follows:
diff --git a/bin/hiera b/bin/hiera
index cc4c8a8..2357275 100755
--- a/bin/hiera
+++ b/bin/hiera
@@ -116,6 +116,10 @@ OptionParser.new do |opts|
options[:resolution_type] = :array
end
+ opts.on("--unique", "-u", "Unique array search") do
+ options[:resolution_type] = :unique_array
+ end
+
opts.on("--hash", "-h", "Hash search") do
options[:resolution_type] = :hash
end
diff --git a/lib/hiera/backend.rb b/lib/hiera/backend.rb
index 3f593b1..cfd1a7e 100644
--- a/lib/hiera/backend.rb
+++ b/lib/hiera/backend.rb
@@ -129,6 +129,8 @@ def parse_answer(data, scope, extra_data={})
def resolve_answer(answer, resolution_type)
case resolution_type
when :array
+ [answer].flatten.compact
+ when :unique_array
[answer].flatten.uniq.compact
when :hash
answer # Hash structure should be preserved