Last change
on this file since 30903 was 30903, checked in by davidb, 8 years ago |
Vagrant provisioning files for a 4-node Hadoop cluster. See README.txt for more details
|
File size:
933 bytes
|
Rev | Line | |
---|
[30903] | 1 | # Boolean check to determine whether a variable is of a given data type. This is equivalent to the `=~` type checks.
|
---|
| 2 | #
|
---|
| 3 | # @example how to check a data type
|
---|
| 4 | # # check a data type
|
---|
| 5 | # foo = 3
|
---|
| 6 | # $bar = [1,2,3]
|
---|
| 7 | # $baz = 'A string!'
|
---|
| 8 | #
|
---|
| 9 | # if $foo.is_a(Integer) {
|
---|
| 10 | # notify { 'foo!': }
|
---|
| 11 | # }
|
---|
| 12 | # if $bar.is_a(Array) {
|
---|
| 13 | # notify { 'bar!': }
|
---|
| 14 | # }
|
---|
| 15 | # if $baz.is_a(String) {
|
---|
| 16 | # notify { 'baz!': }
|
---|
| 17 | # }
|
---|
| 18 | #
|
---|
| 19 | # See the documentation for "The Puppet Type System" for more information about types.
|
---|
| 20 | # See the `assert_type()` function for flexible ways to assert the type of a value.
|
---|
| 21 | #
|
---|
| 22 | Puppet::Functions.create_function(:is_a) do
|
---|
| 23 | dispatch :is_a do
|
---|
| 24 | param 'Any', :value
|
---|
| 25 | param 'Type', :type
|
---|
| 26 | end
|
---|
| 27 |
|
---|
| 28 | def is_a(value, type)
|
---|
| 29 | # See puppet's lib/puppet/pops/evaluator/evaluator_impl.rb eval_MatchExpression
|
---|
| 30 | Puppet::Pops::Types::TypeCalculator.instance?(type, value)
|
---|
| 31 | end
|
---|
| 32 | end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.