First version. Simple type function to use within Puppet DSL.
Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
This commit is contained in:
parent
e9d0b65807
commit
f35fb81998
1 changed files with 33 additions and 0 deletions
33
type.rb
Normal file
33
type.rb
Normal file
|
@ -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 :
|
Loading…
Reference in a new issue