faker 2.1.2 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +41 -7
- data/README.md +2 -2
- data/lib/faker.rb +22 -1
- data/lib/faker/books/dune.rb +12 -2
- data/lib/faker/books/lovecraft.rb +54 -7
- data/lib/faker/default/address.rb +30 -5
- data/lib/faker/default/alphanumeric.rb +45 -7
- data/lib/faker/default/app.rb +16 -1
- data/lib/faker/default/avatar.rb +24 -1
- data/lib/faker/default/bank.rb +12 -2
- data/lib/faker/default/boolean.rb +6 -1
- data/lib/faker/default/chile_rut.rb +20 -2
- data/lib/faker/default/code.rb +22 -3
- data/lib/faker/default/commerce.rb +26 -3
- data/lib/faker/default/company.rb +12 -2
- data/lib/faker/default/crypto_coin.rb +18 -3
- data/lib/faker/default/date.rb +48 -5
- data/lib/faker/default/demographic.rb +6 -1
- data/lib/faker/default/driving_licence.rb +20 -4
- data/lib/faker/default/file.rb +36 -2
- data/lib/faker/default/fillmurray.rb +16 -1
- data/lib/faker/default/finance.rb +6 -1
- data/lib/faker/default/hipster.rb +78 -6
- data/lib/faker/default/id_number.rb +12 -2
- data/lib/faker/default/internet.rb +124 -13
- data/lib/faker/default/invoice.rb +22 -3
- data/lib/faker/default/json.rb +26 -2
- data/lib/faker/default/lorem.rb +120 -10
- data/lib/faker/default/lorem_flickr.rb +69 -5
- data/lib/faker/default/lorem_pixel.rb +26 -1
- data/lib/faker/default/markdown.rb +10 -1
- data/lib/faker/default/measurement.rb +48 -8
- data/lib/faker/default/name.rb +6 -1
- data/lib/faker/default/nhs.rb +6 -1
- data/lib/faker/default/number.rb +81 -11
- data/lib/faker/default/omniauth.rb +84 -5
- data/lib/faker/default/phone_number.rb +6 -1
- data/lib/faker/default/placeholdit.rb +24 -1
- data/lib/faker/default/relationship.rb +6 -1
- data/lib/faker/default/source.rb +22 -3
- data/lib/faker/default/string.rb +6 -1
- data/lib/faker/default/stripe.rb +24 -4
- data/lib/faker/default/time.rb +68 -4
- data/lib/faker/default/twitter.rb +26 -3
- data/lib/faker/default/types.rb +38 -5
- data/lib/faker/default/vehicle.rb +22 -3
- data/lib/faker/default/world_cup.rb +16 -2
- data/lib/faker/games/dota.rb +6 -1
- data/lib/faker/movies/star_wars.rb +6 -1
- data/lib/faker/version.rb +1 -1
- metadata +5 -5
@@ -8,7 +8,22 @@ module Faker
|
|
8
8
|
random_word =~ /\s/ ? word : random_word
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
# rubocop:disable Metrics/ParameterLists
|
12
|
+
def words(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_spaces_allowed = NOT_GIVEN, number: 3, supplemental: false, spaces_allowed: false)
|
13
|
+
# rubocop:enable Metrics/ParameterLists
|
14
|
+
if legacy_number != NOT_GIVEN
|
15
|
+
warn_with_uplevel 'Passing `number` with the 1st argument of `Hipster.words` is deprecated. Use keyword argument like `Hipster.words(number: ...)` instead.', uplevel: 1
|
16
|
+
number = legacy_number
|
17
|
+
end
|
18
|
+
if legacy_supplemental != NOT_GIVEN
|
19
|
+
warn_with_uplevel 'Passing `supplemental` with the 2nd argument of `Hipster.words` is deprecated. Use keyword argument like `Hipster.words(supplemental: ...)` instead.', uplevel: 1
|
20
|
+
supplemental = legacy_supplemental
|
21
|
+
end
|
22
|
+
if legacy_spaces_allowed != NOT_GIVEN
|
23
|
+
warn_with_uplevel 'Passing `spaces_allowed` with the 3rd argument of `Hipster.words` is deprecated. Use keyword argument like `Hipster.words(spaces_allowed: ...)` instead.', uplevel: 1
|
24
|
+
spaces_allowed = legacy_spaces_allowed
|
25
|
+
end
|
26
|
+
|
12
27
|
resolved_num = resolve(number)
|
13
28
|
word_list = (
|
14
29
|
translate('faker.hipster.words') +
|
@@ -22,11 +37,35 @@ module Faker
|
|
22
37
|
words.each_with_index { |w, i| words[i] = word if w =~ /\s/ }
|
23
38
|
end
|
24
39
|
|
25
|
-
|
40
|
+
# rubocop:disable Metrics/ParameterLists
|
41
|
+
def sentence(legacy_word_count = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_random_words_to_add = NOT_GIVEN, word_count: 4, supplemental: false, random_words_to_add: 6)
|
42
|
+
# rubocop:enable Metrics/ParameterLists
|
43
|
+
if legacy_word_count != NOT_GIVEN
|
44
|
+
warn_with_uplevel 'Passing `word_count` with the 1st argument of `Hipster.sentence` is deprecated. Use keyword argument like `Hipster.sentence(word_count: ...)` instead.', uplevel: 1
|
45
|
+
word_count = legacy_word_count
|
46
|
+
end
|
47
|
+
if legacy_supplemental != NOT_GIVEN
|
48
|
+
warn_with_uplevel 'Passing `supplemental` with the 2nd argument of `Hipster.sentence` is deprecated. Use keyword argument like `Hipster.sentence(supplemental: ...)` instead.', uplevel: 1
|
49
|
+
supplemental = legacy_supplemental
|
50
|
+
end
|
51
|
+
if legacy_random_words_to_add != NOT_GIVEN
|
52
|
+
warn_with_uplevel 'Passing `random_words_to_add` with the 3rd argument of `Hipster.sentence` is deprecated. Use keyword argument like `Hipster.sentence(random_words_to_add: ...)` instead.', uplevel: 1
|
53
|
+
random_words_to_add = legacy_random_words_to_add
|
54
|
+
end
|
55
|
+
|
26
56
|
words(number: word_count + rand(random_words_to_add.to_i).to_i, supplemental: supplemental, spaces_allowed: true).join(' ').capitalize + '.'
|
27
57
|
end
|
28
58
|
|
29
|
-
def sentences(number: 3, supplemental: false)
|
59
|
+
def sentences(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 3, supplemental: false)
|
60
|
+
if legacy_number != NOT_GIVEN
|
61
|
+
warn_with_uplevel 'Passing `number` with the 1st argument of `Hipster.sentences` is deprecated. Use keyword argument like `Hipster.sentences(number: ...)` instead.', uplevel: 1
|
62
|
+
number = legacy_number
|
63
|
+
end
|
64
|
+
if legacy_supplemental != NOT_GIVEN
|
65
|
+
warn_with_uplevel 'Passing `supplemental` with the 2nd argument of `Hipster.sentences` is deprecated. Use keyword argument like `Hipster.sentences(supplemental: ...)` instead.', uplevel: 1
|
66
|
+
supplemental = legacy_supplemental
|
67
|
+
end
|
68
|
+
|
30
69
|
[].tap do |sentences|
|
31
70
|
1.upto(resolve(number)) do
|
32
71
|
sentences << sentence(word_count: 3, supplemental: supplemental)
|
@@ -34,11 +73,35 @@ module Faker
|
|
34
73
|
end
|
35
74
|
end
|
36
75
|
|
37
|
-
|
76
|
+
# rubocop:disable Metrics/ParameterLists
|
77
|
+
def paragraph(legacy_sentence_count = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_random_sentences_to_add = NOT_GIVEN, sentence_count: 3, supplemental: false, random_sentences_to_add: 3)
|
78
|
+
# rubocop:enable Metrics/ParameterLists
|
79
|
+
if legacy_sentence_count != NOT_GIVEN
|
80
|
+
warn_with_uplevel 'Passing `sentence_count` with the 1st argument of `Hipster.paragraph` is deprecated. Use keyword argument like `Hipster.paragraph(sentence_count: ...)` instead.', uplevel: 1
|
81
|
+
sentence_count = legacy_sentence_count
|
82
|
+
end
|
83
|
+
if legacy_supplemental != NOT_GIVEN
|
84
|
+
warn_with_uplevel 'Passing `supplemental` with the 2nd argument of `Hipster.paragraph` is deprecated. Use keyword argument like `Hipster.paragraph(supplemental: ...)` instead.', uplevel: 1
|
85
|
+
supplemental = legacy_supplemental
|
86
|
+
end
|
87
|
+
if legacy_random_sentences_to_add != NOT_GIVEN
|
88
|
+
warn_with_uplevel 'Passing `random_sentences_to_add` with the 3rd argument of `Hipster.paragraph` is deprecated. Use keyword argument like `Hipster.paragraph(random_sentences_to_add: ...)` instead.', uplevel: 1
|
89
|
+
random_sentences_to_add = legacy_random_sentences_to_add
|
90
|
+
end
|
91
|
+
|
38
92
|
sentences(number: resolve(sentence_count) + rand(random_sentences_to_add.to_i).to_i, supplemental: supplemental).join(' ')
|
39
93
|
end
|
40
94
|
|
41
|
-
def paragraphs(number: 3, supplemental: false)
|
95
|
+
def paragraphs(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 3, supplemental: false)
|
96
|
+
if legacy_number != NOT_GIVEN
|
97
|
+
warn_with_uplevel 'Passing `number` with the 1st argument of `Hipster.paragraphs` is deprecated. Use keyword argument like `Hipster.paragraphs(number: ...)` instead.', uplevel: 1
|
98
|
+
number = legacy_number
|
99
|
+
end
|
100
|
+
if legacy_supplemental != NOT_GIVEN
|
101
|
+
warn_with_uplevel 'Passing `supplemental` with the 2nd argument of `Hipster.paragraphs` is deprecated. Use keyword argument like `Hipster.paragraphs(supplemental: ...)` instead.', uplevel: 1
|
102
|
+
supplemental = legacy_supplemental
|
103
|
+
end
|
104
|
+
|
42
105
|
[].tap do |paragraphs|
|
43
106
|
1.upto(resolve(number)) do
|
44
107
|
paragraphs << paragraph(sentence_count: 3, supplemental: supplemental)
|
@@ -46,7 +109,16 @@ module Faker
|
|
46
109
|
end
|
47
110
|
end
|
48
111
|
|
49
|
-
def paragraph_by_chars(characters: 256, supplemental: false)
|
112
|
+
def paragraph_by_chars(legacy_characters = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, characters: 256, supplemental: false)
|
113
|
+
if legacy_characters != NOT_GIVEN
|
114
|
+
warn_with_uplevel 'Passing `characters` with the 1st argument of `Hipster.paragraph_by_chars` is deprecated. Use keyword argument like `Hipster.paragraph_by_chars(characters: ...)` instead.', uplevel: 1
|
115
|
+
characters = legacy_characters
|
116
|
+
end
|
117
|
+
if legacy_supplemental != NOT_GIVEN
|
118
|
+
warn_with_uplevel 'Passing `supplemental` with the 2nd argument of `Hipster.paragraph_by_chars` is deprecated. Use keyword argument like `Hipster.paragraph_by_chars(supplemental: ...)` instead.', uplevel: 1
|
119
|
+
supplemental = legacy_supplemental
|
120
|
+
end
|
121
|
+
|
50
122
|
paragraph = paragraph(sentence_count: 3, supplemental: supplemental)
|
51
123
|
|
52
124
|
paragraph += ' ' + paragraph(sentence_count: 3, supplemental: supplemental) while paragraph.length < characters
|
@@ -78,7 +78,12 @@ module Faker
|
|
78
78
|
[id_number, south_african_id_checksum_digit(id_number)].join
|
79
79
|
end
|
80
80
|
|
81
|
-
def brazilian_citizen_number(formatted: false)
|
81
|
+
def brazilian_citizen_number(legacy_formatted = NOT_GIVEN, formatted: false)
|
82
|
+
if legacy_formatted != NOT_GIVEN
|
83
|
+
warn_with_uplevel 'Passing `formatted` with the 1st argument of `IDNumber.brazilian_citizen_number` is deprecated. Use keyword argument like `IDNumber.brazilian_citizen_number(formatted: ...)` instead.', uplevel: 1
|
84
|
+
formatted = legacy_formatted
|
85
|
+
end
|
86
|
+
|
82
87
|
digits = Faker::Number.leading_zero_number(digits: 9) until digits&.match(/(\d)((?!\1)\d)+/)
|
83
88
|
first_digit = brazilian_citizen_number_checksum_digit(digits)
|
84
89
|
second_digit = brazilian_citizen_number_checksum_digit(digits + first_digit)
|
@@ -88,7 +93,12 @@ module Faker
|
|
88
93
|
|
89
94
|
alias brazilian_cpf brazilian_citizen_number
|
90
95
|
|
91
|
-
def brazilian_id(formatted: false)
|
96
|
+
def brazilian_id(legacy_formatted = NOT_GIVEN, formatted: false)
|
97
|
+
if legacy_formatted != NOT_GIVEN
|
98
|
+
warn_with_uplevel 'Passing `formatted` with the 1st argument of `IDNumber.brazilian_id` is deprecated. Use keyword argument like `IDNumber.brazilian_id(formatted: ...)` instead.', uplevel: 1
|
99
|
+
formatted = legacy_formatted
|
100
|
+
end
|
101
|
+
|
92
102
|
digits = Faker::Number.between(to: BRAZILIAN_ID_FROM, from: BRAZILIAN_ID_TO).to_s
|
93
103
|
check_digit = brazilian_id_checksum_digit(digits)
|
94
104
|
number = [digits, check_digit].join
|
@@ -3,7 +3,16 @@
|
|
3
3
|
module Faker
|
4
4
|
class Internet < Base
|
5
5
|
class << self
|
6
|
-
def email(name: nil, separators: nil)
|
6
|
+
def email(legacy_name = NOT_GIVEN, legacy_separators = NOT_GIVEN, name: nil, separators: nil)
|
7
|
+
if legacy_name != NOT_GIVEN
|
8
|
+
warn_with_uplevel 'Passing `name` with the 1st argument of `Internet.email` is deprecated. Use keyword argument like `Internet.email(name: ...)` instead.', uplevel: 1
|
9
|
+
name = legacy_name
|
10
|
+
end
|
11
|
+
if legacy_separators != NOT_GIVEN
|
12
|
+
warn_with_uplevel 'Passing `separators` with the 2nd argument of `Internet.email` is deprecated. Use keyword argument like `Internet.email(separators: ...)` instead.', uplevel: 1
|
13
|
+
separators = legacy_separators
|
14
|
+
end
|
15
|
+
|
7
16
|
if separators
|
8
17
|
[username(specifier: name, separators: separators), domain_name].join('@')
|
9
18
|
else
|
@@ -11,15 +20,34 @@ module Faker
|
|
11
20
|
end
|
12
21
|
end
|
13
22
|
|
14
|
-
def free_email(name: nil)
|
23
|
+
def free_email(legacy_name = NOT_GIVEN, name: nil)
|
24
|
+
if legacy_name != NOT_GIVEN
|
25
|
+
warn_with_uplevel 'Passing `name` with the 1st argument of `Internet.free_email` is deprecated. Use keyword argument like `Internet.free_email(name: ...)` instead.', uplevel: 1
|
26
|
+
name = legacy_name
|
27
|
+
end
|
28
|
+
|
15
29
|
[username(specifier: name), fetch('internet.free_email')].join('@')
|
16
30
|
end
|
17
31
|
|
18
|
-
def safe_email(name: nil)
|
32
|
+
def safe_email(legacy_name = NOT_GIVEN, name: nil)
|
33
|
+
if legacy_name != NOT_GIVEN
|
34
|
+
warn_with_uplevel 'Passing `name` with the 1st argument of `Internet.safe_email` is deprecated. Use keyword argument like `Internet.safe_email(name: ...)` instead.', uplevel: 1
|
35
|
+
name = legacy_name
|
36
|
+
end
|
37
|
+
|
19
38
|
[username(specifier: name), 'example.' + sample(%w[org com net])].join('@')
|
20
39
|
end
|
21
40
|
|
22
|
-
def username(specifier: nil, separators: %w[. _])
|
41
|
+
def username(legacy_specifier = NOT_GIVEN, legacy_separators = NOT_GIVEN, specifier: nil, separators: %w[. _])
|
42
|
+
if legacy_specifier != NOT_GIVEN
|
43
|
+
warn_with_uplevel 'Passing `specifier` with the 1st argument of `Internet.username` is deprecated. Use keyword argument like `Internet.username(specifier: ...)` instead.', uplevel: 1
|
44
|
+
specifier = legacy_specifier
|
45
|
+
end
|
46
|
+
if legacy_separators != NOT_GIVEN
|
47
|
+
warn_with_uplevel 'Passing `separators` with the 2nd argument of `Internet.username` is deprecated. Use keyword argument like `Internet.username(separators: ...)` instead.', uplevel: 1
|
48
|
+
separators = legacy_separators
|
49
|
+
end
|
50
|
+
|
23
51
|
with_locale(:en) do
|
24
52
|
return shuffle(specifier.scan(/[[:word:]]+/)).join(sample(separators)).downcase if specifier.respond_to?(:scan)
|
25
53
|
|
@@ -55,8 +83,44 @@ module Faker
|
|
55
83
|
end
|
56
84
|
end
|
57
85
|
|
58
|
-
|
59
|
-
|
86
|
+
##
|
87
|
+
# Produces a randomized string of characters
|
88
|
+
#
|
89
|
+
# @param [Integer] min_length
|
90
|
+
# @param [Integer] max_length
|
91
|
+
# @param [Boolean] mix_case
|
92
|
+
# @param [Boolean] special_characters
|
93
|
+
#
|
94
|
+
# @return [String]
|
95
|
+
#
|
96
|
+
# @example Faker::Internet.password #=> "Vg5mSvY1UeRg7"
|
97
|
+
# @example Faker::Internet.password(min_length: 8) #=> "YfGjIk0hGzDqS0"
|
98
|
+
# @example Faker::Internet.password(min_length: 10, max_length: 20) #=> "EoC9ShWd1hWq4vBgFw"
|
99
|
+
# @example Faker::Internet.password(min_length: 10, max_length: 20, mix_case: true) #=> "3k5qS15aNmG"
|
100
|
+
# @example Faker::Internet.password(min_length: 10, max_length: 20, mix_case: true, special_characters: true) #=> "*%NkOnJsH4"
|
101
|
+
#
|
102
|
+
# @faker.version 2.1.3
|
103
|
+
# rubocop:disable Metrics/ParameterLists
|
104
|
+
def password(legacy_min_length = NOT_GIVEN, legacy_max_length = NOT_GIVEN, legacy_mix_case = NOT_GIVEN, legacy_special_characters = NOT_GIVEN, min_length: 8, max_length: 16, mix_case: true, special_characters: false)
|
105
|
+
if legacy_min_length != NOT_GIVEN
|
106
|
+
warn_with_uplevel 'Passing `min_length` with the 1st argument of `Internet.password` is deprecated. Use keyword argument like `Internet.password(min_length: ...)` instead.', uplevel: 1
|
107
|
+
min_length = legacy_min_length
|
108
|
+
end
|
109
|
+
if legacy_max_length != NOT_GIVEN
|
110
|
+
warn_with_uplevel 'Passing `max_length` with the 2nd argument of `Internet.password` is deprecated. Use keyword argument like `Internet.password(max_length: ...)` instead.', uplevel: 1
|
111
|
+
max_length = legacy_max_length
|
112
|
+
end
|
113
|
+
if legacy_mix_case != NOT_GIVEN
|
114
|
+
warn_with_uplevel 'Passing `mix_case` with the 3rd argument of `Internet.password` is deprecated. Use keyword argument like `Internet.password(mix_case: ...)` instead.', uplevel: 1
|
115
|
+
mix_case = legacy_mix_case
|
116
|
+
end
|
117
|
+
if legacy_special_characters != NOT_GIVEN
|
118
|
+
warn_with_uplevel 'Passing `special_characters` with the 4th argument of `Internet.password` is deprecated. Use keyword argument like `Internet.password(special_characters: ...)` instead.', uplevel: 1
|
119
|
+
special_characters = legacy_special_characters
|
120
|
+
end
|
121
|
+
|
122
|
+
min_alpha = mix_case ? 2 : 0
|
123
|
+
temp = Lorem.characters(number: min_length, min_alpha: min_alpha)
|
60
124
|
diff_length = max_length - min_length
|
61
125
|
|
62
126
|
if diff_length.positive?
|
@@ -65,8 +129,12 @@ module Faker
|
|
65
129
|
end
|
66
130
|
|
67
131
|
if mix_case
|
132
|
+
alpha_count = 0
|
68
133
|
temp.chars.each_with_index do |char, index|
|
69
|
-
|
134
|
+
if char =~ /[[:alpha:]]/
|
135
|
+
temp[index] = char.upcase if alpha_count.even?
|
136
|
+
alpha_count += 1
|
137
|
+
end
|
70
138
|
end
|
71
139
|
end
|
72
140
|
|
@@ -80,7 +148,12 @@ module Faker
|
|
80
148
|
temp
|
81
149
|
end
|
82
150
|
|
83
|
-
def domain_name(subdomain: false)
|
151
|
+
def domain_name(legacy_subdomain = NOT_GIVEN, subdomain: false)
|
152
|
+
if legacy_subdomain != NOT_GIVEN
|
153
|
+
warn_with_uplevel 'Passing `subdomain` with the 1st argument of `Internet.domain_name` is deprecated. Use keyword argument like `Internet.domain_name(subdomain: ...)` instead.', uplevel: 1
|
154
|
+
subdomain = legacy_subdomain
|
155
|
+
end
|
156
|
+
|
84
157
|
with_locale(:en) do
|
85
158
|
domain_elements = [Char.prepare(domain_word), domain_suffix]
|
86
159
|
domain_elements.unshift(Char.prepare(domain_word)) if subdomain
|
@@ -88,7 +161,12 @@ module Faker
|
|
88
161
|
end
|
89
162
|
end
|
90
163
|
|
91
|
-
def fix_umlauts(string: '')
|
164
|
+
def fix_umlauts(legacy_string = NOT_GIVEN, string: '')
|
165
|
+
if legacy_string != NOT_GIVEN
|
166
|
+
warn_with_uplevel 'Passing `string` with the 1st argument of `Internet.fix_umlauts` is deprecated. Use keyword argument like `Internet.fix_umlauts(string: ...)` instead.', uplevel: 1
|
167
|
+
string = legacy_string
|
168
|
+
end
|
169
|
+
|
92
170
|
Char.fix_umlauts(string)
|
93
171
|
end
|
94
172
|
|
@@ -100,7 +178,12 @@ module Faker
|
|
100
178
|
fetch('internet.domain_suffix')
|
101
179
|
end
|
102
180
|
|
103
|
-
def mac_address(prefix: '')
|
181
|
+
def mac_address(legacy_prefix = NOT_GIVEN, prefix: '')
|
182
|
+
if legacy_prefix != NOT_GIVEN
|
183
|
+
warn_with_uplevel 'Passing `prefix` with the 1st argument of `Internet.mac_address` is deprecated. Use keyword argument like `Internet.mac_address(prefix: ...)` instead.', uplevel: 1
|
184
|
+
prefix = legacy_prefix
|
185
|
+
end
|
186
|
+
|
104
187
|
prefix_digits = prefix.split(':').map { |d| d.to_i(16) }
|
105
188
|
address_digits = Array.new((6 - prefix_digits.size)) { rand(256) }
|
106
189
|
(prefix_digits + address_digits).map { |d| format('%02x', d) }.join(':')
|
@@ -174,11 +257,34 @@ module Faker
|
|
174
257
|
"#{ip_v6_address}/#{rand(1..127)}"
|
175
258
|
end
|
176
259
|
|
177
|
-
def url(host: domain_name, path: "/#{username}", scheme: 'http')
|
260
|
+
def url(legacy_host = NOT_GIVEN, legacy_path = NOT_GIVEN, legacy_scheme = NOT_GIVEN, host: domain_name, path: "/#{username}", scheme: 'http')
|
261
|
+
# rubocop:enable Metrics/ParameterLists
|
262
|
+
if legacy_host != NOT_GIVEN
|
263
|
+
warn_with_uplevel 'Passing `host` with the 1st argument of `Internet.url` is deprecated. Use keyword argument like `Internet.url(host: ...)` instead.', uplevel: 1
|
264
|
+
host = legacy_host
|
265
|
+
end
|
266
|
+
if legacy_path != NOT_GIVEN
|
267
|
+
warn_with_uplevel 'Passing `path` with the 2nd argument of `Internet.url` is deprecated. Use keyword argument like `Internet.url(path: ...)` instead.', uplevel: 1
|
268
|
+
path = legacy_path
|
269
|
+
end
|
270
|
+
if legacy_scheme != NOT_GIVEN
|
271
|
+
warn_with_uplevel 'Passing `scheme` with the 3rd argument of `Internet.url` is deprecated. Use keyword argument like `Internet.url(scheme: ...)` instead.', uplevel: 1
|
272
|
+
scheme = legacy_scheme
|
273
|
+
end
|
274
|
+
|
178
275
|
"#{scheme}://#{host}#{path}"
|
179
276
|
end
|
180
277
|
|
181
|
-
def slug(words: nil, glue: nil)
|
278
|
+
def slug(legacy_words = NOT_GIVEN, legacy_glue = NOT_GIVEN, words: nil, glue: nil)
|
279
|
+
if legacy_words != NOT_GIVEN
|
280
|
+
warn_with_uplevel 'Passing `words` with the 1st argument of `Internet.slug` is deprecated. Use keyword argument like `Internet.slug(words: ...)` instead.', uplevel: 1
|
281
|
+
words = legacy_words
|
282
|
+
end
|
283
|
+
if legacy_glue != NOT_GIVEN
|
284
|
+
warn_with_uplevel 'Passing `glue` with the 2nd argument of `Internet.slug` is deprecated. Use keyword argument like `Internet.slug(glue: ...)` instead.', uplevel: 1
|
285
|
+
glue = legacy_glue
|
286
|
+
end
|
287
|
+
|
182
288
|
glue ||= sample(%w[- _])
|
183
289
|
(words || Faker::Lorem.words(number: 2).join(' ')).delete(',.').gsub(' ', glue).downcase
|
184
290
|
end
|
@@ -187,7 +293,12 @@ module Faker
|
|
187
293
|
shuffle(rand(16**64).to_s(16).rjust(64, '0').chars.to_a).join
|
188
294
|
end
|
189
295
|
|
190
|
-
def user_agent(vendor: nil)
|
296
|
+
def user_agent(legacy_vendor = NOT_GIVEN, vendor: nil)
|
297
|
+
if legacy_vendor != NOT_GIVEN
|
298
|
+
warn_with_uplevel 'Passing `vendor` with the 1st argument of `Internet.user_agent` is deprecated. Use keyword argument like `Internet.user_agent(vendor: ...)` instead.', uplevel: 1
|
299
|
+
vendor = legacy_vendor
|
300
|
+
end
|
301
|
+
|
191
302
|
agent_hash = translate('faker.internet.user_agent')
|
192
303
|
agents = vendor.respond_to?(:to_sym) && agent_hash[vendor.to_sym] || agent_hash[sample(agent_hash.keys)]
|
193
304
|
sample(agents)
|
@@ -6,13 +6,27 @@ module Faker
|
|
6
6
|
|
7
7
|
class << self
|
8
8
|
# Generate random amount between values with 2 decimals
|
9
|
-
def amount_between(from: 0, to: 0)
|
9
|
+
def amount_between(legacy_from = NOT_GIVEN, legacy_to = NOT_GIVEN, from: 0, to: 0)
|
10
|
+
if legacy_from != NOT_GIVEN
|
11
|
+
warn_with_uplevel 'Passing `from` with the 1st argument of `Invoice.amount_between` is deprecated. Use keyword argument like `Invoice.amount_between(from: ...)` instead.', uplevel: 1
|
12
|
+
from = legacy_from
|
13
|
+
end
|
14
|
+
if legacy_to != NOT_GIVEN
|
15
|
+
warn_with_uplevel 'Passing `to` with the 2nd argument of `Invoice.amount_between` is deprecated. Use keyword argument like `Invoice.amount_between(to: ...)` instead.', uplevel: 1
|
16
|
+
to = legacy_to
|
17
|
+
end
|
18
|
+
|
10
19
|
Faker::Base.rand_in_range(from, to).round(2)
|
11
20
|
end
|
12
21
|
|
13
22
|
# International bank slip reference https://en.wikipedia.org/wiki/Creditor_Reference
|
14
23
|
# ref is optional so that we can create unit tests
|
15
|
-
def creditor_reference(ref: '')
|
24
|
+
def creditor_reference(legacy_ref = NOT_GIVEN, ref: '')
|
25
|
+
if legacy_ref != NOT_GIVEN
|
26
|
+
warn_with_uplevel 'Passing `ref` with the 1st argument of `Invoice.creditor_reference` is deprecated. Use keyword argument like `Invoice.creditor_reference(ref: ...)` instead.', uplevel: 1
|
27
|
+
ref = legacy_ref
|
28
|
+
end
|
29
|
+
|
16
30
|
ref = reference if ref.empty?
|
17
31
|
|
18
32
|
'RF' + iban_checksum('RF', ref) + ref
|
@@ -20,7 +34,12 @@ module Faker
|
|
20
34
|
|
21
35
|
# Payment references have some rules in certain countries
|
22
36
|
# ref is optional so that we can create unit tests
|
23
|
-
def reference(ref: '')
|
37
|
+
def reference(legacy_ref = NOT_GIVEN, ref: '')
|
38
|
+
if legacy_ref != NOT_GIVEN
|
39
|
+
warn_with_uplevel 'Passing `ref` with the 1st argument of `Invoice.reference` is deprecated. Use keyword argument like `Invoice.reference(ref: ...)` instead.', uplevel: 1
|
40
|
+
ref = legacy_ref
|
41
|
+
end
|
42
|
+
|
24
43
|
pattern = fetch('invoice.reference.pattern')
|
25
44
|
|
26
45
|
ref = Base.regexify(/#{pattern}/) if ref.empty?
|
data/lib/faker/default/json.rb
CHANGED
@@ -3,7 +3,16 @@ module Faker
|
|
3
3
|
require 'json'
|
4
4
|
|
5
5
|
class << self
|
6
|
-
def shallow_json(width: 3, options: { key: 'Name.first_name', value: 'Name.first_name' })
|
6
|
+
def shallow_json(legacy_width = NOT_GIVEN, legacy_options = NOT_GIVEN, width: 3, options: { key: 'Name.first_name', value: 'Name.first_name' })
|
7
|
+
if legacy_width != NOT_GIVEN
|
8
|
+
warn_with_uplevel 'Passing `width` with the 1st argument of `Json.shallow_json` is deprecated. Use keyword argument like `Json.shallow_json(width: ...)` instead.', uplevel: 1
|
9
|
+
width = legacy_width
|
10
|
+
end
|
11
|
+
if legacy_options != NOT_GIVEN
|
12
|
+
warn_with_uplevel 'Passing `options` with the 2nd argument of `Json.shallow_json` is deprecated. Use keyword argument like `Json.shallow_json(options: ...)` instead.', uplevel: 1
|
13
|
+
options = legacy_options
|
14
|
+
end
|
15
|
+
|
7
16
|
options[:key] = 'Faker::' + options[:key]
|
8
17
|
options[:value] = 'Faker::' + options[:value]
|
9
18
|
|
@@ -11,7 +20,22 @@ module Faker
|
|
11
20
|
JSON.generate(hash)
|
12
21
|
end
|
13
22
|
|
14
|
-
|
23
|
+
# rubocop:disable Metrics/ParameterLists
|
24
|
+
def add_depth_to_json(legacy_json = NOT_GIVEN, legacy_width = NOT_GIVEN, legacy_options = NOT_GIVEN, json: shallow_json, width: 3, options: { key: 'Name.first_name', value: 'Name.first_name' })
|
25
|
+
# rubocop:enable Metrics/ParameterLists
|
26
|
+
if legacy_json != NOT_GIVEN
|
27
|
+
warn_with_uplevel 'Passing `json` with the 1st argument of `Json.add_depth_to_json` is deprecated. Use keyword argument like `Json.add_depth_to_json(json: ...)` instead.', uplevel: 1
|
28
|
+
json = legacy_json
|
29
|
+
end
|
30
|
+
if legacy_width != NOT_GIVEN
|
31
|
+
warn_with_uplevel 'Passing `width` with the 2nd argument of `Json.add_depth_to_json` is deprecated. Use keyword argument like `Json.add_depth_to_json(width: ...)` instead.', uplevel: 1
|
32
|
+
width = legacy_width
|
33
|
+
end
|
34
|
+
if legacy_options != NOT_GIVEN
|
35
|
+
warn_with_uplevel 'Passing `options` with the 3rd argument of `Json.add_depth_to_json` is deprecated. Use keyword argument like `Json.add_depth_to_json(options: ...)` instead.', uplevel: 1
|
36
|
+
options = legacy_options
|
37
|
+
end
|
38
|
+
|
15
39
|
options[:key] = 'Faker::' + options[:key]
|
16
40
|
options[:value] = 'Faker::' + options[:value]
|
17
41
|
|
data/lib/faker/default/lorem.rb
CHANGED
@@ -8,7 +8,16 @@ module Faker
|
|
8
8
|
sample(translate('faker.lorem.words'))
|
9
9
|
end
|
10
10
|
|
11
|
-
def words(number: 3, supplemental: false)
|
11
|
+
def words(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 3, supplemental: false)
|
12
|
+
if legacy_number != NOT_GIVEN
|
13
|
+
warn_with_uplevel 'Passing `number` with the 1st argument of `Lorem.words` is deprecated. Use keyword argument like `Lorem.words(number: ...)` instead.', uplevel: 1
|
14
|
+
number = legacy_number
|
15
|
+
end
|
16
|
+
if legacy_supplemental != NOT_GIVEN
|
17
|
+
warn_with_uplevel 'Passing `supplemental` with the 2nd argument of `Lorem.words` is deprecated. Use keyword argument like `Lorem.words(supplemental: ...)` instead.', uplevel: 1
|
18
|
+
supplemental = legacy_supplemental
|
19
|
+
end
|
20
|
+
|
12
21
|
resolved_num = resolve(number)
|
13
22
|
word_list = (
|
14
23
|
translate('faker.lorem.words') +
|
@@ -22,31 +31,108 @@ module Faker
|
|
22
31
|
sample(Types::CHARACTERS)
|
23
32
|
end
|
24
33
|
|
25
|
-
|
26
|
-
|
34
|
+
##
|
35
|
+
# Produces a random string of alphanumeric characters
|
36
|
+
#
|
37
|
+
# @param [Integer] number
|
38
|
+
# @param [Integer] min_alpha
|
39
|
+
# @param [Integer] min_numeric
|
40
|
+
#
|
41
|
+
# @return [String]
|
42
|
+
#
|
43
|
+
# @example Faker::Lorem.characters #=> "uw1ep04lhs0c4d931n1jmrspprf5wrj85fefue0y7y6m56b6omquh7br7dhqijwlawejpl765nb1716idmp3xnfo85v349pzy2o9rir23y2qhflwr71c1585fnynguiphkjm8p0vktwitcsm16lny7jzp9t4drwav3qmhz4yjq4k04x14gl6p148hulyqioo72tf8nwrxxcclfypz2lc58lsibgfe5w5p0xv95peafjjmm2frkhdc6duoky0aha"
|
44
|
+
# @example Faker::Lorem.characters(number: 10) #=> "ang9cbhoa8"
|
45
|
+
# @example Faker::Lorem.characters(number: 10, min_alpha: 4) #=> "ang9cbhoa8"
|
46
|
+
# @example Faker::Lorem.characters(number: 10, min_alpha: 4, min_numeric: 1) #=> "ang9cbhoa8"
|
47
|
+
#
|
48
|
+
# @faker.version 2.1.3
|
49
|
+
def characters(legacy_number = NOT_GIVEN, number: 255, min_alpha: 0, min_numeric: 0)
|
50
|
+
if legacy_number != NOT_GIVEN
|
51
|
+
warn_with_uplevel 'Passing `number` with the 1st argument of `Lorem.characters` is deprecated. Use keyword argument like `Lorem.characters(number: ...)` instead.', uplevel: 1
|
52
|
+
number = legacy_number
|
53
|
+
end
|
54
|
+
|
55
|
+
Alphanumeric.alphanumeric(number: number, min_alpha: min_alpha, min_numeric: min_numeric)
|
27
56
|
end
|
28
57
|
|
29
58
|
def multibyte
|
30
59
|
sample(translate('faker.lorem.multibyte')).pack('C*').force_encoding('utf-8')
|
31
60
|
end
|
32
61
|
|
33
|
-
|
62
|
+
# rubocop:disable Metrics/ParameterLists
|
63
|
+
def sentence(legacy_word_count = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_random_words_to_add = NOT_GIVEN, word_count: 4, supplemental: false, random_words_to_add: 0)
|
64
|
+
# rubocop:enable Metrics/ParameterLists
|
65
|
+
if legacy_word_count != NOT_GIVEN
|
66
|
+
warn_with_uplevel 'Passing `word_count` with the 1st argument of `Lorem.sentence` is deprecated. Use keyword argument like `Lorem.sentence(word_count: ...)` instead.', uplevel: 1
|
67
|
+
word_count = legacy_word_count
|
68
|
+
end
|
69
|
+
if legacy_supplemental != NOT_GIVEN
|
70
|
+
warn_with_uplevel 'Passing `supplemental` with the 2nd argument of `Lorem.sentence` is deprecated. Use keyword argument like `Lorem.sentence(supplemental: ...)` instead.', uplevel: 1
|
71
|
+
supplemental = legacy_supplemental
|
72
|
+
end
|
73
|
+
if legacy_random_words_to_add != NOT_GIVEN
|
74
|
+
warn_with_uplevel 'Passing `random_words_to_add` with the 3rd argument of `Lorem.sentence` is deprecated. Use keyword argument like `Lorem.sentence(random_words_to_add: ...)` instead.', uplevel: 1
|
75
|
+
random_words_to_add = legacy_random_words_to_add
|
76
|
+
end
|
77
|
+
|
34
78
|
words(number: word_count + rand(random_words_to_add.to_i), supplemental: supplemental).join(' ').capitalize + locale_period
|
35
79
|
end
|
36
80
|
|
37
|
-
def sentences(number: 3, supplemental: false)
|
81
|
+
def sentences(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 3, supplemental: false)
|
82
|
+
if legacy_number != NOT_GIVEN
|
83
|
+
warn_with_uplevel 'Passing `number` with the 1st argument of `Lorem.sentences` is deprecated. Use keyword argument like `Lorem.sentences(number: ...)` instead.', uplevel: 1
|
84
|
+
number = legacy_number
|
85
|
+
end
|
86
|
+
if legacy_supplemental != NOT_GIVEN
|
87
|
+
warn_with_uplevel 'Passing `supplemental` with the 2nd argument of `Lorem.sentences` is deprecated. Use keyword argument like `Lorem.sentences(supplemental: ...)` instead.', uplevel: 1
|
88
|
+
supplemental = legacy_supplemental
|
89
|
+
end
|
90
|
+
|
38
91
|
1.upto(resolve(number)).collect { sentence(word_count: 3, supplemental: supplemental) }
|
39
92
|
end
|
40
93
|
|
41
|
-
|
94
|
+
# rubocop:disable Metrics/ParameterLists
|
95
|
+
def paragraph(legacy_sentence_count = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_random_sentences_to_add = NOT_GIVEN, sentence_count: 3, supplemental: false, random_sentences_to_add: 0)
|
96
|
+
# rubocop:enable Metrics/ParameterLists
|
97
|
+
if legacy_sentence_count != NOT_GIVEN
|
98
|
+
warn_with_uplevel 'Passing `sentence_count` with the 1st argument of `Lorem.paragraph` is deprecated. Use keyword argument like `Lorem.paragraph(sentence_count: ...)` instead.', uplevel: 1
|
99
|
+
sentence_count = legacy_sentence_count
|
100
|
+
end
|
101
|
+
if legacy_supplemental != NOT_GIVEN
|
102
|
+
warn_with_uplevel 'Passing `supplemental` with the 2nd argument of `Lorem.paragraph` is deprecated. Use keyword argument like `Lorem.paragraph(supplemental: ...)` instead.', uplevel: 1
|
103
|
+
supplemental = legacy_supplemental
|
104
|
+
end
|
105
|
+
if legacy_random_sentences_to_add != NOT_GIVEN
|
106
|
+
warn_with_uplevel 'Passing `random_sentences_to_add` with the 3rd argument of `Lorem.paragraph` is deprecated. Use keyword argument like `Lorem.paragraph(random_sentences_to_add: ...)` instead.', uplevel: 1
|
107
|
+
random_sentences_to_add = legacy_random_sentences_to_add
|
108
|
+
end
|
109
|
+
|
42
110
|
sentences(number: resolve(sentence_count) + rand(random_sentences_to_add.to_i), supplemental: supplemental).join(locale_space)
|
43
111
|
end
|
44
112
|
|
45
|
-
def paragraphs(number: 3, supplemental: false)
|
113
|
+
def paragraphs(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 3, supplemental: false)
|
114
|
+
if legacy_number != NOT_GIVEN
|
115
|
+
warn_with_uplevel 'Passing `number` with the 1st argument of `Lorem.paragraphs` is deprecated. Use keyword argument like `Lorem.paragraphs(number: ...)` instead.', uplevel: 1
|
116
|
+
number = legacy_number
|
117
|
+
end
|
118
|
+
if legacy_supplemental != NOT_GIVEN
|
119
|
+
warn_with_uplevel 'Passing `supplemental` with the 2nd argument of `Lorem.paragraphs` is deprecated. Use keyword argument like `Lorem.paragraphs(supplemental: ...)` instead.', uplevel: 1
|
120
|
+
supplemental = legacy_supplemental
|
121
|
+
end
|
122
|
+
|
46
123
|
1.upto(resolve(number)).collect { paragraph(sentence_count: 3, supplemental: supplemental) }
|
47
124
|
end
|
48
125
|
|
49
|
-
def paragraph_by_chars(number: 256, supplemental: false)
|
126
|
+
def paragraph_by_chars(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 256, supplemental: false)
|
127
|
+
if legacy_number != NOT_GIVEN
|
128
|
+
warn_with_uplevel 'Passing `number` with the 1st argument of `Lorem.paragraph_by_chars` is deprecated. Use keyword argument like `Lorem.paragraph_by_chars(number: ...)` instead.', uplevel: 1
|
129
|
+
number = legacy_number
|
130
|
+
end
|
131
|
+
if legacy_supplemental != NOT_GIVEN
|
132
|
+
warn_with_uplevel 'Passing `supplemental` with the 2nd argument of `Lorem.paragraph_by_chars` is deprecated. Use keyword argument like `Lorem.paragraph_by_chars(supplemental: ...)` instead.', uplevel: 1
|
133
|
+
supplemental = legacy_supplemental
|
134
|
+
end
|
135
|
+
|
50
136
|
paragraph = paragraph(sentence_count: 3, supplemental: supplemental)
|
51
137
|
|
52
138
|
paragraph += ' ' + paragraph(sentence_count: 3, supplemental: supplemental) while paragraph.length < number
|
@@ -54,11 +140,35 @@ module Faker
|
|
54
140
|
paragraph[0...number - 1] + '.'
|
55
141
|
end
|
56
142
|
|
57
|
-
|
143
|
+
# rubocop:disable Metrics/ParameterLists
|
144
|
+
def question(legacy_word_count = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, legacy_random_words_to_add = NOT_GIVEN, word_count: 4, supplemental: false, random_words_to_add: 0)
|
145
|
+
# rubocop:enable Metrics/ParameterLists
|
146
|
+
if legacy_word_count != NOT_GIVEN
|
147
|
+
warn_with_uplevel 'Passing `word_count` with the 1st argument of `Lorem.question` is deprecated. Use keyword argument like `Lorem.question(word_count: ...)` instead.', uplevel: 1
|
148
|
+
word_count = legacy_word_count
|
149
|
+
end
|
150
|
+
if legacy_supplemental != NOT_GIVEN
|
151
|
+
warn_with_uplevel 'Passing `supplemental` with the 2nd argument of `Lorem.question` is deprecated. Use keyword argument like `Lorem.question(supplemental: ...)` instead.', uplevel: 1
|
152
|
+
supplemental = legacy_supplemental
|
153
|
+
end
|
154
|
+
if legacy_random_words_to_add != NOT_GIVEN
|
155
|
+
warn_with_uplevel 'Passing `random_words_to_add` with the 3rd argument of `Lorem.question` is deprecated. Use keyword argument like `Lorem.question(random_words_to_add: ...)` instead.', uplevel: 1
|
156
|
+
random_words_to_add = legacy_random_words_to_add
|
157
|
+
end
|
158
|
+
|
58
159
|
words(number: word_count + rand(random_words_to_add), supplemental: supplemental).join(' ').capitalize + locale_question_mark
|
59
160
|
end
|
60
161
|
|
61
|
-
def questions(number: 3, supplemental: false)
|
162
|
+
def questions(legacy_number = NOT_GIVEN, legacy_supplemental = NOT_GIVEN, number: 3, supplemental: false)
|
163
|
+
if legacy_number != NOT_GIVEN
|
164
|
+
warn_with_uplevel 'Passing `number` with the 1st argument of `Lorem.questions` is deprecated. Use keyword argument like `Lorem.questions(number: ...)` instead.', uplevel: 1
|
165
|
+
number = legacy_number
|
166
|
+
end
|
167
|
+
if legacy_supplemental != NOT_GIVEN
|
168
|
+
warn_with_uplevel 'Passing `supplemental` with the 2nd argument of `Lorem.questions` is deprecated. Use keyword argument like `Lorem.questions(supplemental: ...)` instead.', uplevel: 1
|
169
|
+
supplemental = legacy_supplemental
|
170
|
+
end
|
171
|
+
|
62
172
|
1.upto(resolve(number)).collect { question(word_count: 3, supplemental: supplemental) }
|
63
173
|
end
|
64
174
|
|