summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>2011-04-29 15:19:31 +0100
committerKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>2011-04-29 15:19:31 +0100
commitf35fb819988408ad9a2e274bcdd268f7df177f52 (patch)
tree01d143756c13884a0b4156a96931e0d2cdaf5793
parente9d0b65807532903ff5ce8bd8f05149089044264 (diff)
downloadpuppet-stdlib-f35fb819988408ad9a2e274bcdd268f7df177f52.tar.gz
puppet-stdlib-f35fb819988408ad9a2e274bcdd268f7df177f52.tar.bz2
First version. Simple type function to use within Puppet DSL.
Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
-rw-r--r--type.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/type.rb b/type.rb
new file mode 100644
index 0000000..389a056
--- /dev/null
+++ b/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 :