summaryrefslogtreecommitdiff
path: root/code/environments/production/modules/stdlib/lib/puppet/functions/type_of.rb
diff options
context:
space:
mode:
Diffstat (limited to 'code/environments/production/modules/stdlib/lib/puppet/functions/type_of.rb')
-rw-r--r--code/environments/production/modules/stdlib/lib/puppet/functions/type_of.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/code/environments/production/modules/stdlib/lib/puppet/functions/type_of.rb b/code/environments/production/modules/stdlib/lib/puppet/functions/type_of.rb
new file mode 100644
index 0000000..5bed6d5
--- /dev/null
+++ b/code/environments/production/modules/stdlib/lib/puppet/functions/type_of.rb
@@ -0,0 +1,19 @@
+# Returns the type when passed a value.
+#
+# @example how to compare values' types
+# # compare the types of two values
+# if type_of($first_value) != type_of($second_value) { fail("first_value and second_value are different types") }
+# @example how to compare against an abstract type
+# unless type_of($first_value) <= Numeric { fail("first_value must be Numeric") }
+# unless type_of{$first_value) <= Collection[1] { fail("first_value must be an Array or Hash, and contain at least one element") }
+#
+# See the documentation for "The Puppet Type System" for more information about types.
+# See the `assert_type()` function for flexible ways to assert the type of a value.
+#
+# The built-in type() function in puppet is generally preferred over this function
+# this function is provided for backwards compatibility.
+Puppet::Functions.create_function(:type_of) do
+ def type_of(value)
+ Puppet::Pops::Types::TypeCalculator.infer_set(value)
+ end
+end