summaryrefslogtreecommitdiff
path: root/lib/puppet/functions/type_of.rb
diff options
context:
space:
mode:
authorColleen Murphy <cmurphy@users.noreply.github.com>2015-01-13 17:43:19 -0800
committerColleen Murphy <cmurphy@users.noreply.github.com>2015-01-13 17:43:19 -0800
commit712a58a5ce1f8465710dacad49ca2e60c5d0150e (patch)
tree7e56b669bf51eb88ee01a5cbc1f84df5766ebf1c /lib/puppet/functions/type_of.rb
parent80f09623b63cf6946b5913b629911e2c49b5d1dd (diff)
parentcfacdd543e942f7c5d94fd07f14c2f6d8128e83d (diff)
Merge pull request #397 from cyberious/4.6.x
4.6.x
Diffstat (limited to 'lib/puppet/functions/type_of.rb')
-rw-r--r--lib/puppet/functions/type_of.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/puppet/functions/type_of.rb b/lib/puppet/functions/type_of.rb
new file mode 100644
index 0000000..02cdd4d
--- /dev/null
+++ b/lib/puppet/functions/type_of.rb
@@ -0,0 +1,17 @@
+# 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.
+#
+Puppet::Functions.create_function(:type_of) do
+ def type_of(value)
+ Puppet::Pops::Types::TypeCalculator.infer_set(value)
+ end
+end