-
Notifications
You must be signed in to change notification settings - Fork 583
(#20548) Allow an array of resource titles to be passed into the ensure_... #152
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
(#20548) Allow an array of resource titles to be passed into the ensure_... #152
Conversation
…re_resource function This patch allows an array of resource titles to be passed into the ensure_resource function. Each item in the array will be checked for existence and will be created if it doesn't already exist.
items = title.kind_of?(Array) ? title : [].push(title) | ||
|
||
items.each do |item| | ||
Puppet::Parser::Functions.function(:defined_with_params) |
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.
This was in the original implementation, but do you know why this is being done? Is this necessary?
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.
I'm not sure why it's being done, but if there is a better way of doing it, I'd be happy to refactor it.
@@ -37,4 +37,39 @@ | |||
).and_raise_error(Puppet::Error) | |||
end | |||
end | |||
|
|||
describe 'when an array of new resources are passed in' do | |||
it do |
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.
Each one of these expectations should be in a separate it
block; this helps isolate test behavior. I've created a branch that provides an example of how this should be done, at https://github.com/adrienthebo/puppetlabs-stdlib/tree/maint-refactor_ensure_resource_expectations
This splits out the ensure_resource expectations into separate blocks for clarity. Per adrienthebo's recommendation.
Puppet::Parser::Functions.function(:create_resources) | ||
function_create_resources([type.capitalize, { title => params }]) | ||
|
||
items = title.kind_of?(Array) ? title : [title] |
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.
Another slick way to do this is: title = [title].flatten
…_ensure_resource (#20548) Allow an array of resource titles to be passed into the ensure_...
summary: merged into master in 3e59bbd. Thanks again for the contribution! |
...resource function
This patch allows an array of resource titles to be passed into
the ensure_resource function. Each item in the array will be
checked for existence and will be created if it doesn't already
exist.
This is associated with feature request #20548