ffaker 2.22.0 → 2.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Changelog.md +129 -17
- data/Gemfile +15 -0
- data/README.md +3 -2
- data/REFERENCE.md +893 -866
- data/Rakefile +7 -7
- data/ffaker.gemspec +2 -6
- data/lib/ffaker/address.rb +4 -4
- data/lib/ffaker/address_fr.rb +3 -5
- data/lib/ffaker/address_it.rb +1 -4
- data/lib/ffaker/avatar.rb +11 -3
- data/lib/ffaker/bank.rb +1 -1
- data/lib/ffaker/bank_us.rb +37 -0
- data/lib/ffaker/book.rb +10 -2
- data/lib/ffaker/cheesy_lingo.rb +2 -2
- data/lib/ffaker/code.rb +1 -1
- data/lib/ffaker/company.rb +1 -1
- data/lib/ffaker/company_fr.rb +1 -1
- data/lib/ffaker/crypto.rb +14 -0
- data/lib/ffaker/date.rb +9 -0
- data/lib/ffaker/filesystem.rb +12 -2
- data/lib/ffaker/guid.rb +7 -1
- data/lib/ffaker/identification_br.rb +2 -11
- data/lib/ffaker/identification_ec.rb +1 -1
- data/lib/ffaker/identification_es_cl.rb +1 -1
- data/lib/ffaker/identification_kr.rb +10 -3
- data/lib/ffaker/identification_pl.rb +2 -2
- data/lib/ffaker/image.rb +28 -4
- data/lib/ffaker/lorem_ja.rb +1 -1
- data/lib/ffaker/lorem_ru.rb +1 -1
- data/lib/ffaker/movie.rb +1 -1
- data/lib/ffaker/name_fr.rb +4 -3
- data/lib/ffaker/name_pl.rb +2 -2
- data/lib/ffaker/number.rb +4 -0
- data/lib/ffaker/phone_number_de.rb +3 -3
- data/lib/ffaker/skill.rb +1 -1
- data/lib/ffaker/ssn.rb +4 -2
- data/lib/ffaker/string.rb +1 -1
- data/lib/ffaker/utils/module_utils.rb +8 -17
- data/lib/ffaker/utils/unique_utils.rb +9 -5
- data/lib/ffaker/uuid.rb +175 -0
- data/lib/ffaker/version.rb +1 -1
- data/lib/ffaker.rb +61 -191
- data/scripts/reference.rb +8 -10
- data/test/helper.rb +5 -5
- data/test/test_avatar.rb +30 -7
- data/test/test_bank_us.rb +37 -0
- data/test/test_book.rb +29 -0
- data/test/test_crypto.rb +15 -0
- data/test/test_date.rb +11 -1
- data/test/test_filesystem.rb +28 -2
- data/test/test_guid.rb +1 -1
- data/test/test_healthcare_ru.rb +1 -1
- data/test/test_identification.rb +12 -2
- data/test/test_identification_ec.rb +1 -1
- data/test/test_identification_es_mx.rb +3 -1
- data/test/test_identification_it.rb +12 -1
- data/test/test_identification_kr.rb +3 -3
- data/test/test_image.rb +51 -5
- data/test/test_internet.rb +3 -1
- data/test/test_internet_se.rb +3 -1
- data/test/test_lorem_br.rb +1 -1
- data/test/test_lorem_ru.rb +1 -1
- data/test/test_lorem_ua.rb +1 -1
- data/test/test_module_utils.rb +9 -0
- data/test/test_name_ua.rb +1 -1
- data/test/test_number.rb +13 -1
- data/test/test_phone_number_nl.rb +1 -1
- data/test/test_unique_utils.rb +4 -0
- data/test/test_units.rb +6 -6
- data/test/test_units_english.rb +15 -15
- data/test/test_units_metric.rb +15 -15
- data/test/test_uuid.rb +73 -0
- metadata +13 -49
@@ -16,7 +16,7 @@ module FFaker
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def clear
|
19
|
-
instances.
|
19
|
+
instances.each_value(&:clear)
|
20
20
|
instances.clear
|
21
21
|
end
|
22
22
|
end
|
@@ -32,19 +32,23 @@ module FFaker
|
|
32
32
|
|
33
33
|
private
|
34
34
|
|
35
|
-
def method_missing(name, *
|
35
|
+
def method_missing(name, *args, **kwargs)
|
36
36
|
@max_retries.times do
|
37
|
-
result = @generator.public_send(name, *
|
37
|
+
result = @generator.public_send(name, *args, **kwargs)
|
38
38
|
|
39
|
-
next if previous_results[[name,
|
39
|
+
next if previous_results[[name, args, kwargs]].include?(result)
|
40
40
|
|
41
|
-
previous_results[[name,
|
41
|
+
previous_results[[name, args, kwargs]] << result
|
42
42
|
return result
|
43
43
|
end
|
44
44
|
|
45
45
|
raise RetryLimitExceeded, "Retry limit exceeded for #{name}"
|
46
46
|
end
|
47
47
|
|
48
|
+
def respond_to_missing?(name, *args)
|
49
|
+
@generator.respond_to?(name, *args) || super
|
50
|
+
end
|
51
|
+
|
48
52
|
def previous_results
|
49
53
|
@previous_results ||= Hash.new { |hash, key| hash[key] = Set.new }
|
50
54
|
end
|
data/lib/ffaker/uuid.rb
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
module FFaker
|
6
|
+
# UUIDs are a 128-bit value (16 bytes), often represented as a
|
7
|
+
# 32-character hexadecimal string in the format
|
8
|
+
# `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`.
|
9
|
+
#
|
10
|
+
# @note This generates lowercase strings, but UUIDs are case-insensitive.
|
11
|
+
#
|
12
|
+
# @see https://www.rfc-editor.org/rfc/rfc4122#section-4
|
13
|
+
# @see https://datatracker.ietf.org/doc/draft-ietf-uuidrev-rfc4122bis/
|
14
|
+
module UUID
|
15
|
+
extend ModuleUtils
|
16
|
+
extend self
|
17
|
+
|
18
|
+
# > UUID version 4 is meant for generating UUIDs from truly-random or
|
19
|
+
# > pseudo-random numbers.
|
20
|
+
def uuidv4
|
21
|
+
uuid = 0
|
22
|
+
# random_a
|
23
|
+
# > The first 48 bits of the layout that can be filled with random data
|
24
|
+
# > as specified in Section 6.9. Occupies bits 0 through 47 (octets 0-5).
|
25
|
+
uuid |= rand((2**48) - 1) << 80
|
26
|
+
# ver
|
27
|
+
# > The 4 bit version field as defined by Section 4.2, set to 0b0100 (4).
|
28
|
+
# > Occupies bits 48 through 51 of octet 6.
|
29
|
+
uuid |= 0b0100 << 76
|
30
|
+
# random_b
|
31
|
+
# > 12 more bits of the layout that can be filled random data as per
|
32
|
+
# > Section 6.9. Occupies bits 52 through 63 (octets 6-7).
|
33
|
+
uuid |= rand((2**12) - 1) << 64
|
34
|
+
# var
|
35
|
+
# > The 2 bit variant field as defined by Section 4.1, set to 0b10.
|
36
|
+
# > Occupies bits 64 and 65 of octet 8.
|
37
|
+
uuid |= 0b10 << 62
|
38
|
+
# random_c
|
39
|
+
# > The final 62 bits of the layout immediately following the var field
|
40
|
+
# > field to be filled with random data as per Section 6.9. Occupies bits
|
41
|
+
# > 66 through 127 (octets 8-15).
|
42
|
+
uuid |= rand((2**62) - 1)
|
43
|
+
|
44
|
+
as_string(uuid)
|
45
|
+
end
|
46
|
+
|
47
|
+
# > UUID version 6 is a field-compatible version of UUIDv1 Section 5.1,
|
48
|
+
# > reordered for improved DB locality. It is expected that UUIDv6 will
|
49
|
+
# > primarily be used in contexts where UUIDv1 is used. Systems that do not
|
50
|
+
# > involve legacy UUIDv1 SHOULD use UUIDv7 instead.
|
51
|
+
def uuidv6
|
52
|
+
timestamp = rand((2**60) - 1)
|
53
|
+
|
54
|
+
uuid = 0
|
55
|
+
# time_high
|
56
|
+
# > The most significant 32 bits of the 60 bit starting timestamp.
|
57
|
+
# > Occupies bits 0 through 31 (octets 0-3).
|
58
|
+
# @note Shifts 28 bits to remove `time_mid` and `time_low`.
|
59
|
+
uuid |= (timestamp >> 28) << 96
|
60
|
+
# time_mid
|
61
|
+
# > The middle 16 bits of the 60 bit starting timestamp. Occupies bits 32
|
62
|
+
# > through 47 (octets 4-5).
|
63
|
+
# @note Shifts 12 bits to remove `time_low`.
|
64
|
+
uuid |= ((timestamp >> 12) & ((2**16) - 1)) << 80
|
65
|
+
# ver
|
66
|
+
# > The 4 bit version field as defined by Section 4.2, set to 0b0110 (6).
|
67
|
+
# > Occupies bits 48 through 51 of octet 6.
|
68
|
+
uuid |= 0b0110 << 76
|
69
|
+
# time_low
|
70
|
+
# > 12 bits that will contain the least significant 12 bits from the 60
|
71
|
+
# > bit starting timestamp. Occupies bits 52 through 63 (octets 6-7).
|
72
|
+
uuid |= (timestamp & ((2**12) - 1)) << 64
|
73
|
+
# var
|
74
|
+
# > The 2 bit variant field as defined by Section 4.1, set to 0b10.
|
75
|
+
# > Occupies bits 64 and 65 of octet 8.
|
76
|
+
uuid |= 0b10 << 62
|
77
|
+
# clk_seq
|
78
|
+
# > The 14 bits containing the clock sequence. Occupies bits 66 through
|
79
|
+
# > 79 (octets 8-9).
|
80
|
+
#
|
81
|
+
# (earlier in the document)
|
82
|
+
# > The clock sequence and node bits SHOULD be reset to a pseudo-random
|
83
|
+
# > value for each new UUIDv6 generated; however, implementations MAY
|
84
|
+
# > choose to retain the old clock sequence and MAC address behavior from
|
85
|
+
# > Section 5.1.
|
86
|
+
uuid |= rand((2**14) - 1) << 48
|
87
|
+
# node
|
88
|
+
# > 48 bit spatially unique identifier. Occupies bits 80 through 127
|
89
|
+
# > (octets 10-15).
|
90
|
+
uuid |= rand((2**48) - 1)
|
91
|
+
|
92
|
+
as_string(uuid)
|
93
|
+
end
|
94
|
+
|
95
|
+
# > UUID version 7 features a time-ordered value field derived from the
|
96
|
+
# > widely implemented and well known Unix Epoch timestamp source, the
|
97
|
+
# > number of milliseconds since midnight 1 Jan 1970 UTC, leap seconds
|
98
|
+
# > excluded. UUIDv7 generally has improved entropy characteristics over
|
99
|
+
# > UUIDv1 Section 5.1 or UUIDv6 Section 5.6.
|
100
|
+
def uuidv7
|
101
|
+
timestamp = rand((2**48) - 1)
|
102
|
+
|
103
|
+
uuid = 0
|
104
|
+
# unix_ts_ms
|
105
|
+
# > 48 bit big-endian unsigned number of Unix epoch timestamp in
|
106
|
+
# > milliseconds as per Section 6.1. Occupies bits 0 through 47 (octets
|
107
|
+
# > 0-5).
|
108
|
+
uuid |= timestamp << 80
|
109
|
+
# ver
|
110
|
+
# > The 4 bit version field as defined by Section 4.2, set to 0b0111 (7).
|
111
|
+
# > Occupies bits 48 through 51 of octet 6.
|
112
|
+
uuid |= 0b0111 << 76
|
113
|
+
# rand_a
|
114
|
+
# > 12 bits pseudo-random data to provide uniqueness as per Section 6.9
|
115
|
+
# > and/or optional constructs to guarantee additional monotonicity as
|
116
|
+
# > per Section 6.2. Occupies bits 52 through 63 (octets 6-7).
|
117
|
+
uuid |= rand((2**12) - 1) << 64
|
118
|
+
# var
|
119
|
+
# > The 2 bit variant field as defined by Section 4.1, set to 0b10.
|
120
|
+
# > Occupies bits 64 and 65 of octet 8.
|
121
|
+
uuid |= 0b10 << 62
|
122
|
+
# rand_b
|
123
|
+
# > The final 62 bits of pseudo-random data to provide uniqueness as per
|
124
|
+
# > Section 6.9 and/or an optional counter to guarantee additional
|
125
|
+
# > monotonicity as per Section 6.2. Occupies bits 66 through 127 (octets
|
126
|
+
# > 8-15).
|
127
|
+
uuid |= rand((2**62) - 1)
|
128
|
+
|
129
|
+
as_string(uuid)
|
130
|
+
end
|
131
|
+
|
132
|
+
# > UUID version 8 provides an RFC-compatible format for experimental or
|
133
|
+
# > vendor-specific use cases. The only requirement is that the variant and
|
134
|
+
# > version bits MUST be set as defined in Section 4.1 and Section 4.2.
|
135
|
+
# > UUIDv8's uniqueness will be implementation-specific and MUST NOT be
|
136
|
+
# > assumed.
|
137
|
+
# >
|
138
|
+
# > [...] To be clear: UUIDv8 is not a replacement for UUIDv4 Section 5.4
|
139
|
+
# > where all 122 extra bits are filled with random data.
|
140
|
+
def uuidv8
|
141
|
+
uuid = 0
|
142
|
+
# custom_a
|
143
|
+
# > The first 48 bits of the layout that can be filled as an
|
144
|
+
# > implementation sees fit. Occupies bits 0 through 47 (octets 0-5).
|
145
|
+
uuid |= rand((2**48) - 1) << 80
|
146
|
+
# ver
|
147
|
+
# > The 4 bit version field as defined by Section 4.2, set to 0b1000 (8).
|
148
|
+
# > Occupies bits 48 through 51 of octet 6.
|
149
|
+
uuid |= 0b1000 << 76
|
150
|
+
# custom_b
|
151
|
+
# > 12 more bits of the layout that can be filled as an implementation
|
152
|
+
# > sees fit. Occupies bits 52 through 63 (octets 6-7).
|
153
|
+
uuid |= rand((2**12) - 1) << 64
|
154
|
+
# var
|
155
|
+
# > The 2 bit variant field as defined by Section 4.1, set to 0b10.
|
156
|
+
# > Occupies bits 64 and 65 of octet 8.
|
157
|
+
uuid |= 0b10 << 62
|
158
|
+
# custom_c
|
159
|
+
# > The final 62 bits of the layout immediately following the var field
|
160
|
+
# > to be filled as an implementation sees fit. Occupies bits 66 through
|
161
|
+
# > 127 (octets 8-15).
|
162
|
+
uuid |= rand((2**62) - 1)
|
163
|
+
|
164
|
+
as_string(uuid)
|
165
|
+
end
|
166
|
+
|
167
|
+
private
|
168
|
+
|
169
|
+
def as_string(uuid)
|
170
|
+
uuid.to_s(16)
|
171
|
+
.rjust(32, '0')
|
172
|
+
.gsub(/(.{8})(.{4})(.{4})(.{4})(.{12})/, '\1-\2-\3-\4-\5')
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
data/lib/ffaker/version.rb
CHANGED
data/lib/ffaker.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'ffaker/version'
|
4
|
+
require 'pathname'
|
5
|
+
|
3
6
|
module FFaker
|
4
7
|
require_relative 'ffaker/utils/array_utils'
|
5
8
|
require_relative 'ffaker/utils/module_utils'
|
@@ -28,197 +31,64 @@ module FFaker
|
|
28
31
|
letterify(numerify(masks))
|
29
32
|
end
|
30
33
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
autoload :Filesystem, 'ffaker/filesystem'
|
90
|
-
autoload :Food, 'ffaker/food'
|
91
|
-
autoload :FoodPL, 'ffaker/food_pl'
|
92
|
-
autoload :FreedomIpsum, 'ffaker/freedom_ipsum'
|
93
|
-
autoload :Game, 'ffaker/game'
|
94
|
-
autoload :Gender, 'ffaker/gender'
|
95
|
-
autoload :GenderBR, 'ffaker/gender_br'
|
96
|
-
autoload :GenderCN, 'ffaker/gender_cn'
|
97
|
-
autoload :GenderID, 'ffaker/gender_id'
|
98
|
-
autoload :GenderIT, 'ffaker/gender_it'
|
99
|
-
autoload :GenderJA, 'ffaker/gender_ja'
|
100
|
-
autoload :GenderJP, 'ffaker/gender_jp'
|
101
|
-
autoload :GenderKR, 'ffaker/gender_kr'
|
102
|
-
autoload :GenderPL, 'ffaker/gender_pl'
|
103
|
-
autoload :GenderRU, 'ffaker/gender_ru'
|
104
|
-
autoload :Geolocation, 'ffaker/geolocation'
|
105
|
-
autoload :Guid, 'ffaker/guid'
|
106
|
-
autoload :HealthcareIpsum, 'ffaker/healthcare_ipsum'
|
107
|
-
autoload :HealthcareRU, 'ffaker/healthcare_ru'
|
108
|
-
autoload :HipsterIpsum, 'ffaker/hipster_ipsum'
|
109
|
-
autoload :HTMLIpsum, 'ffaker/html_ipsum'
|
110
|
-
autoload :Identification, 'ffaker/identification'
|
111
|
-
autoload :IdentificationBR, 'ffaker/identification_br'
|
112
|
-
autoload :IdentificationES, 'ffaker/identification_es'
|
113
|
-
autoload :IdentificationESCL, 'ffaker/identification_es_cl'
|
114
|
-
autoload :IdentificationESCO, 'ffaker/identification_es_co'
|
115
|
-
autoload :IdentificationIN, 'ffaker/identification_in'
|
116
|
-
autoload :IdentificationIT, 'ffaker/identification_it'
|
117
|
-
autoload :IdentificationKr, 'ffaker/identification_kr'
|
118
|
-
autoload :IdentificationMX, 'ffaker/identification_mx'
|
119
|
-
autoload :IdentificationPL, 'ffaker/identification_pl'
|
120
|
-
autoload :IdentificationTW, 'ffaker/identification_tw'
|
121
|
-
autoload :IdentificationEC, 'ffaker/identification_ec'
|
122
|
-
autoload :Image, 'ffaker/image'
|
123
|
-
autoload :Internet, 'ffaker/internet'
|
124
|
-
autoload :InternetSE, 'ffaker/internet_se'
|
125
|
-
autoload :Job, 'ffaker/job'
|
126
|
-
autoload :JobBR, 'ffaker/job_br'
|
127
|
-
autoload :JobCN, 'ffaker/job_cn'
|
128
|
-
autoload :JobFR, 'ffaker/job_fr'
|
129
|
-
autoload :JobIT, 'ffaker/job_it'
|
130
|
-
autoload :JobJA, 'ffaker/job_ja'
|
131
|
-
autoload :JobKR, 'ffaker/job_kr'
|
132
|
-
autoload :JobVN, 'ffaker/job_vn'
|
133
|
-
autoload :JoJo, 'ffaker/jo_jo'
|
134
|
-
autoload :Locale, 'ffaker/locale'
|
135
|
-
autoload :Lorem, 'ffaker/lorem'
|
136
|
-
autoload :LoremAR, 'ffaker/lorem_ar'
|
137
|
-
autoload :LoremBR, 'ffaker/lorem_br'
|
138
|
-
autoload :LoremCN, 'ffaker/lorem_cn'
|
139
|
-
autoload :LoremFR, 'ffaker/lorem_fr'
|
140
|
-
autoload :LoremIE, 'ffaker/lorem_ie'
|
141
|
-
autoload :LoremIT, 'ffaker/lorem_it'
|
142
|
-
autoload :LoremJA, 'ffaker/lorem_ja'
|
143
|
-
autoload :LoremKR, 'ffaker/lorem_kr'
|
144
|
-
autoload :LoremPL, 'ffaker/lorem_pl'
|
145
|
-
autoload :LoremRU, 'ffaker/lorem_ru'
|
146
|
-
autoload :LoremUA, 'ffaker/lorem_ua'
|
147
|
-
autoload :Movie, 'ffaker/movie'
|
148
|
-
autoload :Music, 'ffaker/music'
|
149
|
-
autoload :Name, 'ffaker/name'
|
150
|
-
autoload :NameAR, 'ffaker/name_ar'
|
151
|
-
autoload :NameBR, 'ffaker/name_br'
|
152
|
-
autoload :NameCN, 'ffaker/name_cn'
|
153
|
-
autoload :NameCS, 'ffaker/name_cs'
|
154
|
-
autoload :NameDA, 'ffaker/name_da'
|
155
|
-
autoload :NameDE, 'ffaker/name_de'
|
156
|
-
autoload :NameES, 'ffaker/name_es'
|
157
|
-
autoload :NameFR, 'ffaker/name_fr'
|
158
|
-
autoload :NameGA, 'ffaker/name_ga'
|
159
|
-
autoload :NameGR, 'ffaker/name_gr'
|
160
|
-
autoload :NameID, 'ffaker/name_id'
|
161
|
-
autoload :NameIN, 'ffaker/name_in'
|
162
|
-
autoload :NameIT, 'ffaker/name_it'
|
163
|
-
autoload :NameJA, 'ffaker/name_ja'
|
164
|
-
autoload :NameKH, 'ffaker/name_kh'
|
165
|
-
autoload :NameKR, 'ffaker/name_kr'
|
166
|
-
autoload :NameMX, 'ffaker/name_mx'
|
167
|
-
autoload :NameNB, 'ffaker/name_nb'
|
168
|
-
autoload :NameNL, 'ffaker/name_nl'
|
169
|
-
autoload :NamePH, 'ffaker/name_ph'
|
170
|
-
autoload :NamePL, 'ffaker/name_pl'
|
171
|
-
autoload :NameRU, 'ffaker/name_ru'
|
172
|
-
autoload :NameSE, 'ffaker/name_se'
|
173
|
-
autoload :NameSN, 'ffaker/name_sn'
|
174
|
-
autoload :NameTH, 'ffaker/name_th'
|
175
|
-
autoload :NameTW, 'ffaker/name_tw'
|
176
|
-
autoload :NameTHEN, 'ffaker/name_th_en'
|
177
|
-
autoload :NameUA, 'ffaker/name_ua'
|
178
|
-
autoload :NameVN, 'ffaker/name_vn'
|
179
|
-
autoload :NatoAlphabet, 'ffaker/nato_alphabet'
|
180
|
-
autoload :Number, 'ffaker/number'
|
181
|
-
autoload :PhoneNumber, 'ffaker/phone_number'
|
182
|
-
autoload :PhoneNumberAU, 'ffaker/phone_number_au'
|
183
|
-
autoload :PhoneNumberBR, 'ffaker/phone_number_br'
|
184
|
-
autoload :PhoneNumberCH, 'ffaker/phone_number_ch'
|
185
|
-
autoload :PhoneNumberCU, 'ffaker/phone_number_cu'
|
186
|
-
autoload :PhoneNumberDA, 'ffaker/phone_number_da'
|
187
|
-
autoload :PhoneNumberDE, 'ffaker/phone_number_de'
|
188
|
-
autoload :PhoneNumberFR, 'ffaker/phone_number_fr'
|
189
|
-
autoload :PhoneNumberID, 'ffaker/phone_number_id'
|
190
|
-
autoload :PhoneNumberIT, 'ffaker/phone_number_it'
|
191
|
-
autoload :PhoneNumberJA, 'ffaker/phone_number_ja'
|
192
|
-
autoload :PhoneNumberKR, 'ffaker/phone_number_kr'
|
193
|
-
autoload :PhoneNumberMX, 'ffaker/phone_number_mx'
|
194
|
-
autoload :PhoneNumberNL, 'ffaker/phone_number_nl'
|
195
|
-
autoload :PhoneNumberPL, 'ffaker/phone_number_pl'
|
196
|
-
autoload :PhoneNumberSE, 'ffaker/phone_number_se'
|
197
|
-
autoload :PhoneNumberSG, 'ffaker/phone_number_sg'
|
198
|
-
autoload :PhoneNumberSN, 'ffaker/phone_number_sn'
|
199
|
-
autoload :PhoneNumberTW, 'ffaker/phone_number_tw'
|
200
|
-
autoload :PhoneNumberUA, 'ffaker/phone_number_ua'
|
201
|
-
autoload :PhoneNumberRU, 'ffaker/phone_number_ru'
|
202
|
-
autoload :Product, 'ffaker/product'
|
203
|
-
autoload :SemVer, 'ffaker/sem_ver'
|
204
|
-
autoload :Skill, 'ffaker/skill'
|
205
|
-
autoload :Sport, 'ffaker/sport'
|
206
|
-
autoload :SportPL, 'ffaker/sport_pl'
|
207
|
-
autoload :SportUS, 'ffaker/sport_us'
|
208
|
-
autoload :SportRU, 'ffaker/sport_ru'
|
209
|
-
autoload :SSN, 'ffaker/ssn'
|
210
|
-
autoload :SSNMX, 'ffaker/ssn_mx'
|
211
|
-
autoload :SSNSE, 'ffaker/ssn_se'
|
212
|
-
autoload :String, 'ffaker/string'
|
213
|
-
autoload :Time, 'ffaker/time'
|
214
|
-
autoload :Tweet, 'ffaker/tweet'
|
215
|
-
autoload :Unit, 'ffaker/unit'
|
216
|
-
autoload :UnitEnglish, 'ffaker/unit_english'
|
217
|
-
autoload :UnitMetric, 'ffaker/unit_metric'
|
218
|
-
autoload :VERSION, 'ffaker/version'
|
219
|
-
autoload :Vehicle, 'ffaker/vehicle'
|
220
|
-
autoload :Venue, 'ffaker/venue'
|
221
|
-
autoload :Youtube, 'ffaker/youtube'
|
34
|
+
autoload_acronyms = {
|
35
|
+
'ar' => 'AR',
|
36
|
+
'au' => 'AU',
|
37
|
+
'aws' => 'AWS',
|
38
|
+
'br' => 'BR',
|
39
|
+
'ca' => 'CA',
|
40
|
+
'ch' => 'CH',
|
41
|
+
'cl' => 'CL',
|
42
|
+
'cn' => 'CN',
|
43
|
+
'co' => 'CO',
|
44
|
+
'cs' => 'CS',
|
45
|
+
'cu' => 'CU',
|
46
|
+
'da' => 'DA',
|
47
|
+
'de' => 'DE',
|
48
|
+
'ec' => 'EC',
|
49
|
+
'en' => 'EN',
|
50
|
+
'es' => 'ES',
|
51
|
+
'fi' => 'FI',
|
52
|
+
'fr' => 'FR',
|
53
|
+
'ga' => 'GA',
|
54
|
+
'gr' => 'GR',
|
55
|
+
'html' => 'HTML',
|
56
|
+
'id' => 'ID',
|
57
|
+
'ie' => 'IE',
|
58
|
+
'in' => 'IN',
|
59
|
+
'it' => 'IT',
|
60
|
+
'ja' => 'JA',
|
61
|
+
'jp' => 'JP',
|
62
|
+
'kh' => 'KH',
|
63
|
+
'kr' => 'KR',
|
64
|
+
'mx' => 'MX',
|
65
|
+
'nb' => 'NB',
|
66
|
+
'nl' => 'NL',
|
67
|
+
'ph' => 'PH',
|
68
|
+
'pl' => 'PL',
|
69
|
+
'ru' => 'RU',
|
70
|
+
'se' => 'SE',
|
71
|
+
'sg' => 'SG',
|
72
|
+
'sn' => 'SN',
|
73
|
+
'ssn' => 'SSN',
|
74
|
+
'th' => 'TH',
|
75
|
+
'tw' => 'TW',
|
76
|
+
'ua' => 'UA',
|
77
|
+
'uk' => 'UK',
|
78
|
+
'us' => 'US',
|
79
|
+
'uuid' => 'UUID',
|
80
|
+
'vn' => 'VN'
|
81
|
+
}
|
82
|
+
|
83
|
+
directory = "#{__dir__}/ffaker"
|
84
|
+
Dir["#{directory}/*.rb"].each do |file_name|
|
85
|
+
relative_file_path = Pathname.new(file_name).relative_path_from(directory).to_s.chomp('.rb')
|
86
|
+
## Don't consider files in sub-directories
|
87
|
+
constant_name = relative_file_path.split('_').map do |part|
|
88
|
+
autoload_acronyms.fetch(part) { part.capitalize }
|
89
|
+
end.join
|
90
|
+
autoload constant_name, file_name
|
91
|
+
end
|
222
92
|
|
223
93
|
# Random Number Generator (RNG) used with ModuleUtils#fetch, #shuffle, #rand
|
224
94
|
# in order to provide deterministic repeatability.
|
data/scripts/reference.rb
CHANGED
@@ -11,8 +11,8 @@ ICONS = {
|
|
11
11
|
warning: '❗'
|
12
12
|
}.freeze
|
13
13
|
|
14
|
-
UTILS_MODULES = %i[ArrayUtils ModuleUtils RandomUtils Random]
|
15
|
-
UTILS_METHODS = %i[k underscore fetch_sample rand shuffle unique luhn_check]
|
14
|
+
UTILS_MODULES = %i[ArrayUtils ModuleUtils RandomUtils Random Version].freeze
|
15
|
+
UTILS_METHODS = %i[k underscore fetch_sample rand shuffle unique luhn_check].freeze
|
16
16
|
|
17
17
|
# Get a list of sections
|
18
18
|
def faker_modules
|
@@ -36,12 +36,14 @@ end
|
|
36
36
|
# Catch deprecation warnings.
|
37
37
|
# This `#warn` overrides Kernel#warn
|
38
38
|
def warn(msg)
|
39
|
-
|
39
|
+
return unless Kernel.instance_variable_get(:@ffaker_warnings)
|
40
|
+
|
41
|
+
Kernel.instance_variable_set(:@ffaker_warnings, Kernel.instance_variable_get(:@ffaker_warnings) << msg)
|
40
42
|
end
|
41
43
|
|
42
44
|
def catch_warnings
|
43
|
-
|
44
|
-
[yield,
|
45
|
+
Kernel.instance_variable_set(:@ffaker_warnings, [])
|
46
|
+
[yield, Kernel.instance_variable_get(:@ffaker_warnings)]
|
45
47
|
end
|
46
48
|
|
47
49
|
def escape(str)
|
@@ -70,11 +72,7 @@ sections = faker_modules.map do |mod|
|
|
70
72
|
examples, warnings = catch_warnings do
|
71
73
|
Array.new(3) { mod.unique.send meth }
|
72
74
|
end
|
73
|
-
right =
|
74
|
-
"#{ICONS[:warning]} *#{warnings.first}*"
|
75
|
-
else
|
76
|
-
(escape examples.join(', ')).to_s
|
77
|
-
end
|
75
|
+
right = warnings.any? ? "#{ICONS[:warning]} *#{warnings.first}*" : (escape examples.join(', ')).to_s
|
78
76
|
rescue StandardError => e
|
79
77
|
right = "#{ICONS[:error]} #{e.class}: #{e.message}"
|
80
78
|
end
|
data/test/helper.rb
CHANGED
@@ -14,7 +14,7 @@ module DeterministicHelper
|
|
14
14
|
# the internal Random Number Generator state and compared the results of
|
15
15
|
# each execution to make sure they are the same.
|
16
16
|
def assert_deterministic(options = {}, &block)
|
17
|
-
raise ArgumentError, 'Must pass a block' unless
|
17
|
+
raise ArgumentError, 'Must pass a block' unless block
|
18
18
|
|
19
19
|
options = { message: 'Results are not repeatable' }.merge(options)
|
20
20
|
|
@@ -35,7 +35,7 @@ module DeterministicHelper
|
|
35
35
|
end
|
36
36
|
operator_name += '_or_equal_to' if operator[1] == '='
|
37
37
|
|
38
|
-
define_method "assert_#{operator_name}" do |got, expected|
|
38
|
+
define_method :"assert_#{operator_name}" do |got, expected|
|
39
39
|
assert(
|
40
40
|
got.public_send(operator, expected),
|
41
41
|
"Expected #{operator} \"#{expected}\", but got #{got}"
|
@@ -56,8 +56,8 @@ module DeterministicHelper
|
|
56
56
|
end
|
57
57
|
|
58
58
|
%w[less_than_or_equal_to between].each do |method_name|
|
59
|
-
define_method "assert_random_#{method_name}" do |*args, &block|
|
60
|
-
assert_random(block) { send "assert_#{method_name}", block.call, *args }
|
59
|
+
define_method :"assert_random_#{method_name}" do |*args, &block|
|
60
|
+
assert_random(block) { send :"assert_#{method_name}", block.call, *args }
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
@@ -76,7 +76,7 @@ module DeterministicHelper
|
|
76
76
|
# }
|
77
77
|
def assert_methods_are_deterministic(klass, *methods)
|
78
78
|
Array(methods).each do |meth|
|
79
|
-
define_method "test_#{meth}_is_deterministic" do
|
79
|
+
define_method :"test_#{meth}_is_deterministic" do
|
80
80
|
assert_deterministic(message: "Results from `#{klass}.#{meth}` are not repeatable") do
|
81
81
|
klass.send(meth)
|
82
82
|
end
|
data/test/test_avatar.rb
CHANGED
@@ -18,40 +18,63 @@ class TestAvatar < Test::Unit::TestCase
|
|
18
18
|
@tester.image)
|
19
19
|
end
|
20
20
|
|
21
|
+
def test_image_output_with_keyword_arguments
|
22
|
+
output = capture_output do
|
23
|
+
@tester.image(format: 'jpg')
|
24
|
+
end
|
25
|
+
|
26
|
+
assert_equal ['', ''], output
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_image_with_slug_as_positional_argument
|
30
|
+
assert_equal("#{ROBOHASH}/foobar.png?size=300x300", @tester.image('foobar'))
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_image_output_with_positional_arguments
|
34
|
+
output = capture_output do
|
35
|
+
@tester.image('foobar')
|
36
|
+
end
|
37
|
+
|
38
|
+
assert_equal(
|
39
|
+
['', "Positional arguments for Avatar#image are deprecated. Please use keyword arguments.\n"],
|
40
|
+
output
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
21
44
|
def test_avatar_with_param
|
22
|
-
assert_equal("#{ROBOHASH}/faker.png?size=300x300", @tester.image('faker'))
|
45
|
+
assert_equal("#{ROBOHASH}/faker.png?size=300x300", @tester.image(slug: 'faker'))
|
23
46
|
end
|
24
47
|
|
25
48
|
def test_avatar_with_correct_size
|
26
49
|
assert_equal("#{ROBOHASH}/faker.png?size=150x320",
|
27
|
-
@tester.image('faker', '150x320'))
|
50
|
+
@tester.image(slug: 'faker', size: '150x320'))
|
28
51
|
end
|
29
52
|
|
30
53
|
def test_avatar_with_incorrect_size
|
31
54
|
assert_raise ArgumentError do
|
32
|
-
@tester.image(
|
55
|
+
@tester.image(size: '150x320z')
|
33
56
|
end
|
34
57
|
end
|
35
58
|
|
36
59
|
def test_avatar_with_supported_format
|
37
60
|
assert_equal("#{ROBOHASH}/faker.jpg?size=300x300",
|
38
|
-
@tester.image('faker', '300x300', 'jpg'))
|
61
|
+
@tester.image(slug: 'faker', size: '300x300', format: 'jpg'))
|
39
62
|
end
|
40
63
|
|
41
64
|
def test_avatar_with_incorrect_format
|
42
65
|
assert_raise ArgumentError do
|
43
|
-
@tester.image(
|
66
|
+
@tester.image(size: '300x300', format: 'wrong_format')
|
44
67
|
end
|
45
68
|
end
|
46
69
|
|
47
70
|
def test_avatar_with_correct_background
|
48
71
|
assert_equal("#{ROBOHASH}/faker.png?size=300x300&bgset=bg1",
|
49
|
-
@tester.image('faker', '300x300', 'png', '1'))
|
72
|
+
@tester.image(slug: 'faker', size: '300x300', format: 'png', bgset: '1'))
|
50
73
|
end
|
51
74
|
|
52
75
|
def test_avatar_with_incorrect_background
|
53
76
|
assert_raise ArgumentError do
|
54
|
-
@tester.image('faker', '300x300', 'png', 'not_a_number')
|
77
|
+
@tester.image(slug: 'faker', size: '300x300', format: 'png', bgset: 'not_a_number')
|
55
78
|
end
|
56
79
|
end
|
57
80
|
end
|