Skip to content

Commit 1abba4c

Browse files
committed
Namespace function fqdn_rand_string()
1 parent 6935f8c commit 1abba4c

File tree

3 files changed

+46
-32
lines changed

3 files changed

+46
-32
lines changed
Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,14 @@
11
# frozen_string_literal: true
22

3-
# @summary
4-
# Generates a random alphanumeric string. Combining the `$fqdn` fact and an
5-
# optional seed for repeatable randomness.
6-
#
7-
# Optionally, you can specify a character set for the function (defaults to alphanumeric).
3+
# THIS FILE WAS GENERATED BY `rake regenerate_unamespaced_shims`
4+
5+
# @summary DEPRECATED. Use the namespaced function [`stdlib::fqdn_rand_string`](#stdlibfqdn_rand_string) instead.
86
Puppet::Functions.create_function(:fqdn_rand_string) do
9-
# @param length The length of the resulting string.
10-
# @param charset The character set to use.
11-
# @param The seed for repeatable randomness.
12-
#
13-
# @return [String]
14-
#
15-
# @example Example Usage:
16-
# fqdn_rand_string(10)
17-
# fqdn_rand_string(10, 'ABCDEF!@$%^')
18-
# fqdn_rand_string(10, '', 'custom seed')
19-
dispatch :fqdn_rand_string do
20-
param 'Integer[1]', :length
21-
optional_param 'String', :charset
22-
optional_repeated_param 'Any', :seed
7+
dispatch :deprecation_gen do
8+
repeated_param 'Any', :args
239
end
24-
25-
def fqdn_rand_string(length, charset = '', *seed)
26-
charset = charset.chars.to_a
27-
28-
charset = (0..9).map(&:to_s) + ('A'..'Z').to_a + ('a'..'z').to_a if charset.empty?
29-
30-
rand_string = ''
31-
length.times do |current|
32-
rand_string += charset[call_function('fqdn_rand', charset.size, (seed + [current + 1]).join(':'))]
33-
end
34-
35-
rand_string
10+
def deprecation_gen(*args)
11+
call_function('deprecation', 'fqdn_rand_string', 'This function is deprecated, please use stdlib::fqdn_rand_string instead.')
12+
call_function('stdlib::fqdn_rand_string', *args)
3613
end
3714
end
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# frozen_string_literal: true
2+
3+
# @summary
4+
# Generates a random alphanumeric string. Combining the `$fqdn` fact and an
5+
# optional seed for repeatable randomness.
6+
#
7+
# Optionally, you can specify a character set for the function (defaults to alphanumeric).
8+
Puppet::Functions.create_function(:'stdlib::fqdn_rand_string') do
9+
# @param length The length of the resulting string.
10+
# @param charset The character set to use.
11+
# @param The seed for repeatable randomness.
12+
#
13+
# @return [String]
14+
#
15+
# @example Example Usage:
16+
# stdlib::fqdn_rand_string(10)
17+
# stdlib::fqdn_rand_string(10, 'ABCDEF!@$%^')
18+
# stdlib::fqdn_rand_string(10, '', 'custom seed')
19+
dispatch :fqdn_rand_string do
20+
param 'Integer[1]', :length
21+
optional_param 'String', :charset
22+
optional_repeated_param 'Any', :seed
23+
end
24+
25+
def fqdn_rand_string(length, charset = '', *seed)
26+
charset = charset.chars.to_a
27+
28+
charset = (0..9).map(&:to_s) + ('A'..'Z').to_a + ('a'..'z').to_a if charset.empty?
29+
30+
rand_string = ''
31+
length.times do |current|
32+
rand_string += charset[call_function('fqdn_rand', charset.size, (seed + [current + 1]).join(':'))]
33+
end
34+
35+
rand_string
36+
end
37+
end

spec/functions/fqdn_rand_string_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require 'spec_helper'
44

5-
describe 'fqdn_rand_string' do
5+
describe 'stdlib::fqdn_rand_string' do
66
let(:default_charset) { %r{\A[a-zA-Z0-9]{100}\z} }
77

88
it { is_expected.not_to be_nil }

0 commit comments

Comments
 (0)