X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fgetparam.rb;h=59ef7691a1d126e64437ecd35af828ae0c6c29d2;hb=30caaa85aed7015ca0d77216bff175eebd917eb7;hp=6d510069f9066cf58fed3c0730b0d3bf9b0e7998;hpb=ad88f67c13ae0f1a08936dad643f1e3509ab5f40;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/stdlib/lib/puppet/parser/functions/getparam.rb b/3rdparty/modules/stdlib/lib/puppet/parser/functions/getparam.rb index 6d510069f..59ef7691a 100644 --- a/3rdparty/modules/stdlib/lib/puppet/parser/functions/getparam.rb +++ b/3rdparty/modules/stdlib/lib/puppet/parser/functions/getparam.rb @@ -3,32 +3,56 @@ require 'puppet/parser/functions' Puppet::Parser::Functions.newfunction(:getparam, :type => :rvalue, - :doc => <<-'ENDOFDOC' -Takes a resource reference and name of the parameter and -returns value of resource's parameter. + :doc => <<-'DOC' + @summary + Returns the value of a resource's parameter. -*Examples:* + @return + value of a resource's parameter. - define example_resource($param) { - } + Takes a resource reference and name of the parameter and + returns value of resource's parameter. Note that user defined + resource types are evaluated lazily. - example_resource { "example_resource_instance": - param => "param_value" - } + @example Example Usage: - getparam(Example_resource["example_resource_instance"], "param") + # define a resource type with a parameter + define example_resource($param) { + } -Would return: param_value -ENDOFDOC -) do |vals| + # declare an instance of that type + example_resource { "example_resource_instance": + param => "'the value we are getting in this example''" + } + + # Because of order of evaluation, a second definition is needed + # that will be evaluated after the first resource has been declared + # + define example_get_param { + # This will notice the value of the parameter + notice(getparam(Example_resource["example_resource_instance"], "param")) + } + + # Declare an instance of the second resource type - this will call notice + example_get_param { 'show_notify': } + + Would notice: 'the value we are getting in this example' + + > **Note** that since Puppet 4.0.0 it is possible to get a parameter value by using its data type + and the [ ] operator. The example below is equivalent to a call to getparam(): + ```Example_resource['example_resource_instance']['param']`` + + DOC + ) do |vals| reference, param = vals raise(ArgumentError, 'Must specify a reference') unless reference - raise(ArgumentError, 'Must specify name of a parameter') unless param and param.instance_of? String + raise(ArgumentError, 'Must specify name of a parameter') unless param && param.instance_of?(String) return '' if param.empty? - if resource = findresource(reference.to_s) - return resource[param] if resource[param] + resource = findresource(reference.to_s) + if resource + return resource[param] unless resource[param].nil? end return ''