Sha256: 2e9a2fff40129628ed15e20a62e0b410bc5ee788cbdc57b99d80bed0edebda65

Contents?: true

Size: 1.16 KB

Versions: 20

Compression:

Stored size: 1.16 KB

Contents

#
# 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 :

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
puppet-retrospec-1.8.0 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/type3x.rb
puppet-retrospec-1.7.0 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/type3x.rb
puppet-retrospec-1.6.1 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/type3x.rb
puppet-retrospec-1.6.0 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/type3x.rb
puppet-retrospec-1.5.0 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/type3x.rb
puppet-retrospec-1.4.1 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/type3x.rb
puppet-retrospec-1.4.0 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/type3x.rb
puppet-retrospec-1.3.2 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/type3x.rb
puppet-retrospec-1.3.1 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/type3x.rb
puppet-retrospec-1.3.0 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/type3x.rb
puppet-retrospec-1.2.1 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/type3x.rb
puppet-retrospec-1.2.0 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/type3x.rb
puppet-retrospec-1.1.0 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/type3x.rb
puppet-retrospec-1.0.0 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/type3x.rb
puppet-retrospec-0.12.1 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/type3x.rb
puppet-retrospec-0.12.0 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/type3x.rb
puppet-retrospec-0.11.0 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/type3x.rb
puppet-retrospec-0.10.0 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/type3x.rb
puppet-retrospec-0.9.1 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/type3x.rb
puppet-retrospec-0.9.0 spec/fixtures/modules/stdlib/lib/puppet/parser/functions/type3x.rb