Last change
on this file since 30903 was 30903, checked in by davidb, 8 years ago |
Vagrant provisioning files for a 4-node Hadoop cluster. See README.txt for more details
|
File size:
1.2 KB
|
Rev | Line | |
---|
[30903] | 1 | #
|
---|
| 2 | # type3x.rb
|
---|
| 3 | #
|
---|
| 4 |
|
---|
| 5 | module Puppet::Parser::Functions
|
---|
| 6 | newfunction(:type3x, :type => :rvalue, :doc => <<-EOS
|
---|
| 7 | DEPRECATED: This function will be removed when puppet 3 support is dropped; please migrate to the new parser's typing system.
|
---|
| 8 |
|
---|
| 9 | Returns the type when passed a value. Type can be one of:
|
---|
| 10 |
|
---|
| 11 | * string
|
---|
| 12 | * array
|
---|
| 13 | * hash
|
---|
| 14 | * float
|
---|
| 15 | * integer
|
---|
| 16 | * boolean
|
---|
| 17 | EOS
|
---|
| 18 | ) do |args|
|
---|
| 19 | raise(Puppet::ParseError, "type3x(): Wrong number of arguments " +
|
---|
| 20 | "given (#{args.size} for 1)") if args.size < 1
|
---|
| 21 |
|
---|
| 22 | value = args[0]
|
---|
| 23 |
|
---|
| 24 | klass = value.class
|
---|
| 25 |
|
---|
| 26 | if not [TrueClass, FalseClass, Array, Bignum, Fixnum, Float, Hash, String].include?(klass)
|
---|
| 27 | raise(Puppet::ParseError, 'type3x(): Unknown type')
|
---|
| 28 | end
|
---|
| 29 |
|
---|
| 30 | klass = klass.to_s # Ugly ...
|
---|
| 31 |
|
---|
| 32 | # We note that Integer is the parent to Bignum and Fixnum ...
|
---|
| 33 | result = case klass
|
---|
| 34 | when /^(?:Big|Fix)num$/ then 'integer'
|
---|
| 35 | when /^(?:True|False)Class$/ then 'boolean'
|
---|
| 36 | else klass
|
---|
| 37 | end
|
---|
| 38 |
|
---|
| 39 | if result == "String" then
|
---|
| 40 | if value == value.to_i.to_s then
|
---|
| 41 | result = "Integer"
|
---|
| 42 | elsif value == value.to_f.to_s then
|
---|
| 43 | result = "Float"
|
---|
| 44 | end
|
---|
| 45 | end
|
---|
| 46 |
|
---|
| 47 | return result.downcase
|
---|
| 48 | end
|
---|
| 49 | end
|
---|
| 50 |
|
---|
| 51 | # vim: set ts=2 sw=2 et :
|
---|
Note:
See
TracBrowser
for help on using the repository browser.