Bug #15628
Need way to pass array to class to APPEND to defaults
| Status: | Needs Decision | Start date: | 07/20/2012 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | % Done: | 0% | ||
| Category: | - | |||
| Target version: | - | |||
| Affected Puppet version: | Branch: | |||
| Keywords: | ux | |||
Description
A way to pass an array to a class so that it would APPEND that array to the default array for that class would be excellent.
Related issues
History
#1
Updated by Bill Tong 11 months ago
A better explanation:
Say you have a class that accepts three arguments: a boolean, a string, and an array. Each of these has a default. The array’s default is quite big.
If I then create a class and want to override the boolean, I can. The string? I can.
But for the array I only want to add one extra element. At the moment I have to copy the long list of defaults, and add the element I want to add, and pass that back.
Being able to say “add this to the defaults” would be helpful.
#2
Updated by eric sorenson 10 months ago
- Status changed from Unreviewed to Needs Decision
- Assignee set to Randall Hansen
- Keywords set to dsl
Yes, right now the common pattern for this amongst the puppet pro svc folk is referred to as the “underscore-real pattern”, after the workaround they use :
define my::define ($value1 = "string", $value2 = ["dummy array"]) {
$value2_real_default = [ "Real default1", "Real default2"]
if $value2[0] != "dummy array" {
$value2_real = [ $value2_real_default, $value2 ]
}
else {
$value2_real = [ $value2_real_default ]
}
notify { $title:
message => inline_template('<%= value2_real.join("\n") %>')
}
}
my::define { 'no_overrides': }
my::define { 'array_override':
value2 => [ 'New value1', 'New value2' ]
}
This is… not wonderful. It’d be nice to have some syntax for doing this but I’m not sure what it would look like.
Randall, any thoughts? As I see it, we have a choice:
– to control it on the sending side (the array_override resource above would be able to indicate that ‘New value1’ and ‘New value2’ should override whatever my::define provides by default)
– control on the receiving side, where my::define gets to decide whether additional parameters to $value2 append to, rather than replacing, what it thinks the defaults should be
– refine this code pattern into something polished and worth publishing but don’t make changes into the underlying implementation.
#3
Updated by Randall Hansen 9 months ago
- Assignee changed from Randall Hansen to J.D. Welch
#4
Updated by J.D. Welch 8 months ago
- Keywords changed from dsl to dsl backlog
#5
Updated by J.D. Welch 8 months ago
- Keywords changed from dsl backlog to backlog
#6
Updated by eric sorenson 8 months ago
- Keywords changed from backlog to ux