Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion functions/deferrable_epp.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# have to explicitly pass the entire scope to the client.
#
function stdlib::deferrable_epp(String $template, Hash $variables) >> Variant[String, Sensitive[String], Deferred] {
if $variables.any |$key, $value| { $value.is_a(Deferred) } {
if $variables.hash_values.any |$value| { $value.is_a(Deferred) } {
Deferred(
'inline_epp',
[find_template($template).file, $variables],
Expand Down
26 changes: 26 additions & 0 deletions lib/puppet/functions/hash_values.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

# This function will return list of Hash values, the return value will be Array
# NOTE : This function is expecting only Hash and return value will be Array
#
# @example :
# $hash = {
# "key1" => "value1",
# "key2" => { "key2.1" => "value2.1"}
# }
# $hash.hash_value
#
# Output : ["value1", "value2.1"]
#
Puppet::Functions.create_function(:hash_values) do
dispatch :hash_values do
param 'Hash', :options
return_type 'Array'
end

def hash_values(options)
options.each_with_object([]) do |(_k, v), values|
v.is_a?(Hash) ? values.concat(hash_values(v)) : (values << v)
end
end
end
14 changes: 14 additions & 0 deletions spec/functions/hash_values_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'hash_values' do
# please note that these tests are examples only
# you will need to replace the params and return value
# with your expectations
it { is_expected.to run.with_params({}).and_return([]) }
it { is_expected.to run.with_params({ 'key' => 'value' }).and_return(['value']) }
it { is_expected.to run.with_params({ 'key' => { 'key1' => 'value1', 'key2' => 'value2' } }).and_return(['value1', 'value2']) }
it { is_expected.to run.with_params(2).and_raise_error(StandardError) }
it { is_expected.to run.with_params(nil).and_raise_error(StandardError) }
end