Added ensure_* functions#869
Conversation
|
Hm, doesn't seem like broken tests were caused by my changes. |
|
@pegasd I'm seeing similar failures in my windows modules on Travis :-( Suspect Travis just us a christmas present :-( |
|
@pegasd Tracking this in https://tickets.puppetlabs.com/browse/MODULES-6339 |
|
Can we retest this please? I'm assuming the issue has been fixed. |
hlindberg
left a comment
There was a problem hiding this comment.
I don't think this belongs in stdlib. Please publish this in your own module and namespace the function.
| # } | ||
| # } | ||
| dispatch :ensure do | ||
| param 'Variant[String, Boolean]', :ensure_param |
There was a problem hiding this comment.
If you change the type to Enum[present, absent] you would not need to check that in an else since you are guaranteed your method gets called with only one of those two values.
|
The original can be written: A more useful general purpose function would be something like a simple switch/swap value like: Closing this for now since commits and PR also must be marked with the ticket number. |
This CR adds a new function to case the ensureable property to a resource
specific value. e.g.
* stdlib::ensure('present', 'service') == 'running'
* stdlib::ensure('present', 'directory') == 'directory'
This is usefull when you want to pass ensure to a custome class and
ensure all the resource get the correct value e.g.
```
class foo(
Enum['present', 'absent'] $ensure = 'present'
) {
file {'/some/dir':
ensure => stdlib::ensure($ensure, 'directory')
}
file {'/some/file':
ensure => stdlib::ensure($ensure, 'file')
}
file {'/some/link':
ensure => stdlib::ensure($ensure, 'link')
}
service {'some-service':
ensure => stdlib::ensure($ensure, 'service')
}
```
something similar to this was discussed in puppetlabs#869
This CR adds a new function to case the ensureable property to a resource
specific value. e.g.
* stdlib::ensure('present', 'service') == 'running'
* stdlib::ensure('present', 'directory') == 'directory'
This is usefull when you want to pass ensure to a custome class and
ensure all the resource get the correct value e.g.
```
class foo(
Enum['present', 'absent'] $ensure = 'present'
) {
file {'/some/dir':
ensure => stdlib::ensure($ensure, 'directory')
}
file {'/some/file':
ensure => stdlib::ensure($ensure, 'file')
}
file {'/some/link':
ensure => stdlib::ensure($ensure, 'link')
}
service {'some-service':
ensure => stdlib::ensure($ensure, 'service')
}
```
something similar to this was discussed in puppetlabs#869
This CR adds a new function to case the ensureable property to a resource
specific value. e.g.
* stdlib::ensure('present', 'service') == 'running'
* stdlib::ensure('present', 'directory') == 'directory'
This is usefull when you want to pass ensure to a custome class and
ensure all the resource get the correct value e.g.
```
class foo(
Enum['present', 'absent'] $ensure = 'present'
) {
file {'/some/dir':
ensure => stdlib::ensure($ensure, 'directory')
}
file {'/some/file':
ensure => stdlib::ensure($ensure, 'file')
}
file {'/some/link':
ensure => stdlib::ensure($ensure, 'link')
}
service {'some-service':
ensure => stdlib::ensure($ensure, 'service')
}
```
something similar to this was discussed in puppetlabs#869
This CR adds a new function to case the ensureable property to a resource
specific value. e.g.
* stdlib::ensure('present', 'service') == 'running'
* stdlib::ensure('present', 'directory') == 'directory'
This is usefull when you want to pass ensure to a custome class and
ensure all the resource get the correct value e.g.
```
class foo(
Enum['present', 'absent'] $ensure = 'present'
) {
file {'/some/dir':
ensure => stdlib::ensure($ensure, 'directory')
}
file {'/some/file':
ensure => stdlib::ensure($ensure, 'file')
}
file {'/some/link':
ensure => stdlib::ensure($ensure, 'link')
}
service {'some-service':
ensure => stdlib::ensure($ensure, 'service')
}
```
something similar to this was discussed in puppetlabs#869
After seeing lots of these
I decided to implement helper functions and abstract this logic away.
Usage is as follows: