source: other-projects/hathitrust/vagrant-solr-cluster/trunk/modules/stdlib/lib/puppet/functions/is_a.rb@ 30960

Last change on this file since 30960 was 30960, checked in by davidb, 7 years ago

Switch to using Puppet to provision machine. Strongly based on files developed for spark-hdfs cluster

File size: 933 bytes
Line 
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#
22Puppet::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
32end
Note: See TracBrowser for help on using the repository browser.