Sha256: 292761eaf1d35d8d2fd7aee43df61b7a8c13f4484248109e1f95d7d6939e7630

Contents?: true

Size: 1001 Bytes

Versions: 41

Compression:

Stored size: 1001 Bytes

Contents

# Returns a new instance of a data type.
# (The documentation is maintained in the corresponding 3.x stub)
#
# @since 4.5.0
#
Puppet::Functions.create_function(:new, Puppet::Functions::InternalFunction) do

  dispatch :new_instance do
    scope_param
    param          'Type', :type
    repeated_param 'Any',  :args
    optional_block_param
  end

  def new_instance(scope, t, *args)
    return args[0] if args.size == 1 && !t.is_a?(Puppet::Pops::Types::PInitType) && t.instance?(args[0])
    result = catch :undefined_value do
      new_function_for_type(t, scope).call(scope, *args)
    end
    assert_type(t, result)
    return block_given? ? yield(result) : result
  end

  def new_function_for_type(t, scope)
    @new_function_cache ||= Hash.new() {|hsh, key| hsh[key] = key.new_function.new(scope, loader) }
    @new_function_cache[t]
  end

  def assert_type(type, value)
    Puppet::Pops::Types::TypeAsserter.assert_instance_of(['Converted value from %s.new()', type], type, value)
  end
end

Version data entries

41 entries across 41 versions & 2 rubygems

Version Path
puppet-5.3.7 lib/puppet/functions/new.rb
puppet-5.3.7-x86-mingw32 lib/puppet/functions/new.rb
puppet-5.3.7-x64-mingw32 lib/puppet/functions/new.rb
puppet-5.3.7-universal-darwin lib/puppet/functions/new.rb
puppet-5.3.6 lib/puppet/functions/new.rb
puppet-5.3.6-x86-mingw32 lib/puppet/functions/new.rb
puppet-5.3.6-x64-mingw32 lib/puppet/functions/new.rb
puppet-5.3.6-universal-darwin lib/puppet/functions/new.rb
puppet-5.3.5 lib/puppet/functions/new.rb
puppet-5.3.5-x86-mingw32 lib/puppet/functions/new.rb
puppet-5.3.5-x64-mingw32 lib/puppet/functions/new.rb
puppet-5.3.5-universal-darwin lib/puppet/functions/new.rb
puppet-5.3.4 lib/puppet/functions/new.rb
puppet-5.3.4-x86-mingw32 lib/puppet/functions/new.rb
puppet-5.3.4-x64-mingw32 lib/puppet/functions/new.rb
puppet-5.3.4-universal-darwin lib/puppet/functions/new.rb
puppet-5.3.3 lib/puppet/functions/new.rb
puppet-5.3.3-x86-mingw32 lib/puppet/functions/new.rb
puppet-5.3.3-x64-mingw32 lib/puppet/functions/new.rb
puppet-5.3.3-universal-darwin lib/puppet/functions/new.rb