summaryrefslogtreecommitdiff
path: root/lib/puppet/parser/functions/type.rb
diff options
context:
space:
mode:
authorKen Barber <ken@bob.sh>2011-04-29 16:52:14 +0200
committerKen Barber <ken@bob.sh>2011-04-30 15:59:55 +0200
commit09abea2d47b09b9e8933a1c27c7a454c77760e83 (patch)
treeb2d9f4fd054103b10b976f8b0bc3ca99ef7c2004 /lib/puppet/parser/functions/type.rb
parent352bac3703f012c88f2317307cc51d22dc80ebcc (diff)
Moved type.rb
Diffstat (limited to 'lib/puppet/parser/functions/type.rb')
-rw-r--r--lib/puppet/parser/functions/type.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/puppet/parser/functions/type.rb b/lib/puppet/parser/functions/type.rb
new file mode 100644
index 0000000..389a056
--- /dev/null
+++ b/lib/puppet/parser/functions/type.rb
@@ -0,0 +1,33 @@
+#
+# type.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:type, :type => :rvalue, :doc => <<-EOS
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "type(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+
+ klass = value.class
+
+ if not [Array, Bignum, Fixnum, Float, Hash, String].include?(klass)
+ raise(Puppet::ParseError, 'type(): 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'
+ else klass
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :