Sha256: 2102b7dd8f5d67022e24ea4e961dd7ccd23bab20d3717d14e548afe65b6879f0

Contents?: true

Size: 1.02 KB

Versions: 50

Compression:

Stored size: 1.02 KB

Contents

Puppet::Parser::Functions::newfunction(
  :assert_type,
  :type => :rvalue,
  :arity => -3,
  :doc => "Returns the given value if it is an instance of the given type, and raises an error otherwise.
Optionally, if a block is given (accepting two parameters), it will be called instead of raising
an error. This to enable giving the user richer feedback, or to supply a default value.

Example: assert that `$b` is a non empty `String` and assign to `$a`:

  $a = assert_type(String[1], $b)

Example using custom error message:

  $a = assert_type(String[1], $b) |$expected, $actual| {
    fail('The name cannot be empty')
  }

Example, using a warning and a default:

  $a = assert_type(String[1], $b) |$expected, $actual| {
    warning('Name is empty, using default')
    'anonymous'
  }

See the documentation for 'The Puppet Type System' for more information about types.
- since Puppet 3.7
- requires future parser/evaluator
") do |args|
  function_fail(["assert_type() is only available when parser/evaluator future is in effect"])
end

Version data entries

50 entries across 50 versions & 2 rubygems

Version Path
puppet-retrospec-0.12.2 vendor/gems/puppet-3.7.3/lib/puppet/parser/functions/assert_type.rb
puppet-3.8.7 lib/puppet/parser/functions/assert_type.rb
puppet-3.8.7-x86-mingw32 lib/puppet/parser/functions/assert_type.rb
puppet-3.8.7-x64-mingw32 lib/puppet/parser/functions/assert_type.rb
puppet-3.8.6 lib/puppet/parser/functions/assert_type.rb
puppet-3.8.6-x86-mingw32 lib/puppet/parser/functions/assert_type.rb
puppet-retrospec-0.12.1 vendor/gems/puppet-3.7.3/lib/puppet/parser/functions/assert_type.rb
puppet-3.8.6-x64-mingw32 lib/puppet/parser/functions/assert_type.rb
puppet-retrospec-0.12.0 vendor/gems/puppet-3.7.3/lib/puppet/parser/functions/assert_type.rb
puppet-3.8.5 lib/puppet/parser/functions/assert_type.rb
puppet-3.8.5-x86-mingw32 lib/puppet/parser/functions/assert_type.rb
puppet-3.8.5-x64-mingw32 lib/puppet/parser/functions/assert_type.rb
puppet-3.8.4 lib/puppet/parser/functions/assert_type.rb
puppet-3.8.4-x86-mingw32 lib/puppet/parser/functions/assert_type.rb
puppet-3.8.4-x64-mingw32 lib/puppet/parser/functions/assert_type.rb
puppet-retrospec-0.11.0 vendor/gems/puppet-3.7.3/lib/puppet/parser/functions/assert_type.rb
puppet-retrospec-0.10.0 vendor/gems/puppet-3.7.3/lib/puppet/parser/functions/assert_type.rb
puppet-retrospec-0.9.1 vendor/gems/puppet-3.7.3/lib/puppet/parser/functions/assert_type.rb
puppet-retrospec-0.9.0 vendor/gems/puppet-3.7.3/lib/puppet/parser/functions/assert_type.rb
puppet-retrospec-0.8.1 vendor/gems/puppet-3.7.3/lib/puppet/parser/functions/assert_type.rb