-
Notifications
You must be signed in to change notification settings - Fork 582
(CONT-1023) - Enhancing deferrable_epp to support nested hash #1359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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.nested_values | ||
# | ||
# Output : ["value1", "value2.1"] | ||
# | ||
Puppet::Functions.create_function(:nested_values) do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happened to all new functions being namespaced?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest namespacing it without creating a shim as this hasn't made it to a release yet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Damned! Yes, to all of this 😪 |
||
dispatch :nested_values do | ||
param 'Hash', :options | ||
return_type 'Array' | ||
end | ||
|
||
def nested_values(options) | ||
options.each_with_object([]) do |(_k, v), values| | ||
v.is_a?(Hash) ? values.concat(nested_values(v)) : (values << v) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe 'nested_values' do | ||
# please note that these tests are examples only | ||
# you will need to replace the params and return value | ||
# with your expectations | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These comments should not have made it in. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. addressed in #1363. |
||
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({ 'key1' => 'value1', 'key2' => { 'key1' => 'value21', 'key2' => 'value22' }, 'key3' => 'value3' }).and_return(['value1', 'value21', 'value22', 'value3']) } | ||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two lines could be reworded to remove the repetition about the return value.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed here