X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fdefined_with_params.rb;h=cc2b90a43572eadc098d57740e0897654d9ce009;hb=30caaa85aed7015ca0d77216bff175eebd917eb7;hp=c45a9dfa88922c23861d338a00aa421ad7255912;hpb=6963202b4b62c2816655ac9532521b018fdf83bd;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/stdlib/lib/puppet/parser/functions/defined_with_params.rb b/3rdparty/modules/stdlib/lib/puppet/parser/functions/defined_with_params.rb index c45a9dfa8..cc2b90a43 100644 --- a/3rdparty/modules/stdlib/lib/puppet/parser/functions/defined_with_params.rb +++ b/3rdparty/modules/stdlib/lib/puppet/parser/functions/defined_with_params.rb @@ -3,24 +3,30 @@ require 'puppet/parser/functions' Puppet::Parser::Functions.newfunction(:defined_with_params, :type => :rvalue, - :doc => <<-'ENDOFDOC' -Takes a resource reference and an optional hash of attributes. + :doc => <<-DOC + @summary + Takes a resource reference and an optional hash of attributes. -Returns true if a resource with the specified attributes has already been added -to the catalog, and false otherwise. + Returns `true` if a resource with the specified attributes has already been added + to the catalog, and `false` otherwise. - user { 'dan': - ensure => present, - } + ``` + user { 'dan': + ensure => present, + } - if ! defined_with_params(User[dan], {'ensure' => 'present' }) { - user { 'dan': ensure => present, } - } -ENDOFDOC -) do |vals| + if ! defined_with_params(User[dan], {'ensure' => 'present' }) { + user { 'dan': ensure => present, } + } + ``` + + @return [Boolean] + returns `true` or `false` +DOC + ) do |vals| reference, params = vals raise(ArgumentError, 'Must specify a reference') unless reference - if (! params) || params == '' + if !params || params == '' params = {} end ret = false @@ -31,19 +37,20 @@ ENDOFDOC type_name, title = Puppet::Resource.type_and_title(reference, nil) type = Puppet::Pops::Evaluator::Runtime3ResourceSupport.find_resource_type_or_class(find_global_scope, type_name.downcase) elsif reference.is_a?(Puppet::Resource) - type = reference.resource_type + type = reference.type title = reference.title else raise(ArgumentError, "Reference is not understood: '#{reference.class}'") end - #end workaround + # end workaround else type = reference.to_s title = nil end - if resource = findresource(type, title) - matches = params.collect do |key, value| + resource = findresource(type, title) + if resource + matches = params.map do |key, value| # eql? avoids bugs caused by monkeypatching in puppet resource_is_undef = resource[key].eql?(:undef) || resource[key].nil? value_is_undef = value.eql?(:undef) || value.nil?