Sha256: ed490229f6c99a53787fd80b290c76a5f2eac2ffcb7a68e99969f5c1aee33ceb

Contents?: true

Size: 950 Bytes

Versions: 19

Compression:

Stored size: 950 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 = assert_type(t, new_function_for_type(t, scope).call(scope, *args))
    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

19 entries across 19 versions & 2 rubygems

Version Path
bolt-0.17.1 vendored/puppet/lib/puppet/functions/new.rb
bolt-0.17.0 vendored/puppet/lib/puppet/functions/new.rb
bolt-0.16.4 vendored/puppet/lib/puppet/functions/new.rb
bolt-0.16.3 vendored/puppet/lib/puppet/functions/new.rb
bolt-0.16.2 vendored/puppet/lib/puppet/functions/new.rb
puppet-5.4.0 lib/puppet/functions/new.rb
puppet-5.4.0-x86-mingw32 lib/puppet/functions/new.rb
puppet-5.4.0-x64-mingw32 lib/puppet/functions/new.rb
puppet-5.4.0-universal-darwin lib/puppet/functions/new.rb
bolt-0.16.1 vendored/puppet/lib/puppet/functions/new.rb
bolt-0.16.0 vendored/puppet/lib/puppet/functions/new.rb
bolt-0.15.0 vendored/puppet/lib/puppet/functions/new.rb
bolt-0.14.0 vendored/puppet/lib/puppet/functions/new.rb
bolt-0.13.0 vendored/puppet/lib/puppet/functions/new.rb
bolt-0.12.0 vendored/puppet/lib/puppet/functions/new.rb
bolt-0.11.0 vendored/puppet/lib/puppet/functions/new.rb
bolt-0.10.0 vendored/puppet/lib/puppet/functions/new.rb
bolt-0.9.0 vendored/puppet/lib/puppet/functions/new.rb
bolt-0.8.0 vendored/puppet/lib/puppet/functions/new.rb