summaryrefslogtreecommitdiff
path: root/lib/puppet/parser/functions/type3x.rb
diff options
context:
space:
mode:
authorTravis Fields <travis@puppetlabs.com>2015-01-13 17:16:10 -0800
committerTravis Fields <travis@puppetlabs.com>2015-01-13 17:16:10 -0800
commitac3e51bac57ecc4b29965b5df5f10c2934b61cd0 (patch)
tree71413b757c0e0ec4d21727386979354e50099fdc /lib/puppet/parser/functions/type3x.rb
parent80f09623b63cf6946b5913b629911e2c49b5d1dd (diff)
parent8db1f2e2f082cd688fa061fd6840cd0cea747232 (diff)
Merge branch 'master' into 4.5.x
Diffstat (limited to 'lib/puppet/parser/functions/type3x.rb')
-rw-r--r--lib/puppet/parser/functions/type3x.rb51
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/puppet/parser/functions/type3x.rb b/lib/puppet/parser/functions/type3x.rb
new file mode 100644
index 0000000..0800b4a
--- /dev/null
+++ b/lib/puppet/parser/functions/type3x.rb
@@ -0,0 +1,51 @@
+#
+# type3x.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:type3x, :type => :rvalue, :doc => <<-EOS
+DEPRECATED: This function will be removed when puppet 3 support is dropped; please migrate to the new parser's typing system.
+
+Returns the type when passed a value. Type can be one of:
+
+* string
+* array
+* hash
+* float
+* integer
+* boolean
+ EOS
+ ) do |args|
+ raise(Puppet::ParseError, "type3x(): Wrong number of arguments " +
+ "given (#{args.size} for 1)") if args.size < 1
+
+ value = args[0]
+
+ klass = value.class
+
+ if not [TrueClass, FalseClass, Array, Bignum, Fixnum, Float, Hash, String].include?(klass)
+ raise(Puppet::ParseError, 'type3x(): Unknown type')
+ end
+
+ klass = klass.to_s # Ugly ...
+
+ # We note that Integer is the parent to Bignum and Fixnum ...
+ result = case klass
+ when /^(?:Big|Fix)num$/ then 'integer'
+ when /^(?:True|False)Class$/ then 'boolean'
+ else klass
+ end
+
+ if result == "String" then
+ if value == value.to_i.to_s then
+ result = "Integer"
+ elsif value == value.to_f.to_s then
+ result = "Float"
+ end
+ end
+
+ return result.downcase
+ end
+end
+
+# vim: set ts=2 sw=2 et :