X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Ffqdn_rand_string.rb;fp=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Ffqdn_rand_string.rb;h=ee45236b34bab9a83c1084029fd41ac8c7bf3437;hb=131e09855e065be940e104d9ab0f18940cc76257;hp=2bb1287e06be42f612cdd4805bc98282804e68c3;hpb=407d322498f4fde815abf381007fbecfe5c10b2b;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/stdlib/lib/puppet/parser/functions/fqdn_rand_string.rb b/3rdparty/modules/stdlib/lib/puppet/parser/functions/fqdn_rand_string.rb index 2bb1287e0..ee45236b3 100644 --- a/3rdparty/modules/stdlib/lib/puppet/parser/functions/fqdn_rand_string.rb +++ b/3rdparty/modules/stdlib/lib/puppet/parser/functions/fqdn_rand_string.rb @@ -1,4 +1,4 @@ -Puppet::Parser::Functions::newfunction( +Puppet::Parser::Functions.newfunction( :fqdn_rand_string, :arity => -2, :type => :rvalue, @@ -12,23 +12,24 @@ Puppet::Parser::Functions::newfunction( string from this function, but a given node's result will be the same every time unless its hostname changes.) Adding a SEED can be useful if you need more than one unrelated string. CHARSET will default to alphanumeric if - `undef` or an empty string.") do |args| - raise(ArgumentError, "fqdn_rand_string(): wrong number of arguments (0 for 1)") if args.size == 0 - Puppet::Parser::Functions.function('is_integer') - raise(ArgumentError, "fqdn_rand_string(): first argument must be a positive integer") unless function_is_integer([args[0]]) and args[0].to_i > 0 - raise(ArgumentError, "fqdn_rand_string(): second argument must be undef or a string") unless args[1].nil? or args[1].is_a? String + `undef` or an empty string.", +) do |args| + raise(ArgumentError, 'fqdn_rand_string(): wrong number of arguments (0 for 1)') if args.empty? + Puppet::Parser::Functions.function('is_integer') + raise(ArgumentError, 'fqdn_rand_string(): first argument must be a positive integer') unless function_is_integer([args[0]]) && args[0].to_i > 0 + raise(ArgumentError, 'fqdn_rand_string(): second argument must be undef or a string') unless args[1].nil? || args[1].is_a?(String) - Puppet::Parser::Functions.function('fqdn_rand') + Puppet::Parser::Functions.function('fqdn_rand') - length = args.shift.to_i - charset = args.shift.to_s.chars.to_a + length = args.shift.to_i + charset = args.shift.to_s.chars.to_a - charset = (0..9).map { |i| i.to_s } + ('A'..'Z').to_a + ('a'..'z').to_a if charset.empty? + charset = (0..9).map { |i| i.to_s } + ('A'..'Z').to_a + ('a'..'z').to_a if charset.empty? - rand_string = '' - for current in 1..length - rand_string << charset[function_fqdn_rand([charset.size, (args + [current.to_s]).join(':')]).to_i] - end + rand_string = '' + for current in 1..length # rubocop:disable Style/For : An each loop would not work correctly in this circumstance + rand_string << charset[function_fqdn_rand([charset.size, (args + [current.to_s]).join(':')]).to_i] + end - rand_string + rand_string end