faker 3.7.1 → 3.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78d4c5b5bfa5fdebf9bf09a55173557109e4e55ca1fdd6458a065157d5d3a380
4
- data.tar.gz: cdd36c405854936c9281c0c181194c12765956d36b2ff91a20520f308c4a1a71
3
+ metadata.gz: 38a9d198febc038719036f12b99ba3b7f72a88bcc63335ff7246823732880d95
4
+ data.tar.gz: 7a01cb7591744939b8704abdf2f40e953eddb01307faea36b6a8ca000db9454d
5
5
  SHA512:
6
- metadata.gz: c09170d534ec923fd18fca0c4d21e6f1c76c85f9fe83b7d98b3e8695263c3f446ff6f0576e52b0f99b7ac75381b2c7585b80b9a29d9bb29200465267fbfe7337
7
- data.tar.gz: e2cdc970656cc8abddc2bacf5219262be2fd4ae4a22dcaaf3279028fb7d67fa0f4b5db149f63ca72337e4022a50a51c38074960a390beb69ec05cf62860cc2e2
6
+ metadata.gz: c2305eff5122ee4e9754333e8c11488a6fd2c6efc6985e8cf05f80118c2ae079aab1c0e81eee20414a6fa2cc156bf2c0a8d542792ff96d18dfaafa06965aac3d
7
+ data.tar.gz: 7f07790d5f5b8e4b3815fa0a9c32d28098bcf7f46f2b8d3c87e60600e61f0435b3c7bcf3260fc7b377e7765b29cc254c867530c455ab657bb869a825bd82e393
data/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # Changelog
2
2
 
3
+ ## [v3.8.0](https://github.com/faker-ruby/faker/tree/v3.8.0) (2026-04-16)
4
+
5
+ * Add Lazy loading config by @stefannibrasil and @thdaraujo in https://github.com/faker-ruby/faker/pull/3244
6
+
7
+ ### Enabling lazy load
8
+
9
+ This version introduces lazy loading. It means users will only pay for what they use. Faker [loads 2x faster](https://github.com/faker-ruby/faker/blob/main/experiments/lazy_load.md) when it's enabled.
10
+
11
+ Lazy loading the generators is disabled by default. To enable it, choose one of the configuration options below:
12
+
13
+ #### 1 - Set lazy load as a Faker Config
14
+
15
+ `Faker::Config.lazy_loading = true`
16
+
17
+ #### 2 - Set lazy load as an environment variable
18
+
19
+ `FAKER_LAZY_LOAD = 1`
20
+
21
+ We hope you get to see the improvement by enabling it. Please file a bug report for any issues!
22
+
23
+ Thanks to @jeremyevans for the mentoring, and to @thdaraujo for pairing and code reviews.
24
+
25
+ **Full Changelog**: https://github.com/faker-ruby/faker/compare/v3.7.1...v3.8.0
26
+
27
+ -----------------------
28
+
3
29
  ## [v3.7.1](https://github.com/faker-ruby/faker/tree/v3.7.1) (2026-04-14)
4
30
 
5
31
  Thanks to all contributors!
@@ -26,6 +52,8 @@ Thanks to all contributors!
26
52
 
27
53
  **Full Changelog**: https://github.com/faker-ruby/faker/compare/v3.6.1...v3.7.1
28
54
 
55
+ --------------------------------
56
+
29
57
  ## [v3.6.1](https://github.com/faker-ruby/faker/tree/v3.6.1) (2026-03-04)
30
58
 
31
59
  It's almost Spring time in the Northern hemisphere 🌸
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ class Blockchain
5
+ if Faker::Config.lazy_loading?
6
+ Faker.lazy_load(self)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ class Books
5
+ if Faker::Config.lazy_loading?
6
+ Faker.lazy_load(self)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ class Creature
5
+ if Faker::Config.lazy_loading?
6
+ Faker.lazy_load(self)
7
+ end
8
+ end
9
+ end
@@ -14,7 +14,7 @@ module Faker
14
14
  # @faker.version 3.2.1
15
15
  def heading
16
16
  level = rand(1..6)
17
- "<h#{level}>#{Lorem.word.capitalize}</h#{level}>"
17
+ "<h#{level}>#{Faker::Lorem.word.capitalize}</h#{level}>"
18
18
  end
19
19
 
20
20
  ##
@@ -97,7 +97,7 @@ module Faker
97
97
  #
98
98
  # @faker.version 3.2.1
99
99
  def code
100
- "<code>#{Lorem.sentence(word_count: 1)}</code>"
100
+ "<code>#{Faker::Lorem.sentence(word_count: 1)}</code>"
101
101
  end
102
102
 
103
103
  ##
@@ -165,7 +165,7 @@ module Faker
165
165
  # Faker::HTML.element(tag: 'div', content: "This is a div with XSS attributes.", attributes: {class: 'xss', onclick: "alert('XSS')"}) #=> "<div class=\"xss\" onclick=\"alert('XSS')\">This is a div with XSS attributes.</div>"
166
166
  #
167
167
  # @faker.version 3.2.1
168
- def element(tag: 'div', content: Lorem.sentence(word_count: 3), attributes: { class: Lorem.word, onclick: "#{Lorem.word}()" })
168
+ def element(tag: 'div', content: Faker::Lorem.sentence(word_count: 3), attributes: { class: Faker::Lorem.word, onclick: "#{Faker::Lorem.word}()" })
169
169
  attribute_string = attributes.map { |key, value| "#{key}=\"#{value}\"" }.join(' ')
170
170
  "<#{tag} #{attribute_string}>#{content}</#{tag}>"
171
171
  end
@@ -58,7 +58,7 @@ module Faker
58
58
  #
59
59
  # @faker.version 2.1.3
60
60
  def character
61
- sample(Types::CHARACTERS)
61
+ sample(Faker::Types::CHARACTERS)
62
62
  end
63
63
 
64
64
  ##
@@ -78,7 +78,7 @@ module Faker
78
78
  #
79
79
  # @faker.version 2.1.3
80
80
  def characters(number: 255, min_alpha: 0, min_numeric: 0)
81
- Alphanumeric.alphanumeric(number: number, min_alpha: min_alpha, min_numeric: min_numeric)
81
+ Faker::Alphanumeric.alphanumeric(number: number, min_alpha: min_alpha, min_numeric: min_numeric)
82
82
  end
83
83
 
84
84
  ##
@@ -13,7 +13,7 @@ module Faker
13
13
  #
14
14
  # @faker.version 1.8.0
15
15
  def headers
16
- "#{fetch('markdown.headers')} #{Lorem.word.capitalize}"
16
+ "#{fetch('markdown.headers')} #{Faker::Lorem.word.capitalize}"
17
17
  end
18
18
 
19
19
  ##
@@ -95,7 +95,7 @@ module Faker
95
95
  #
96
96
  # @faker.version 1.8.0
97
97
  def block_code
98
- "```ruby\n#{Lorem.sentence(word_count: 1)}\n```"
98
+ "```ruby\n#{Faker::Lorem.sentence(word_count: 1)}\n```"
99
99
  end
100
100
 
101
101
  ##
@@ -110,7 +110,7 @@ module Faker
110
110
  def table
111
111
  table = []
112
112
  3.times do
113
- table << "#{Lorem.word} | #{Lorem.word} | #{Lorem.word}"
113
+ table << "#{Faker::Lorem.word} | #{Faker::Lorem.word} | #{Faker::Lorem.word}"
114
114
  end
115
115
  table.insert(1, '---- | ---- | ----')
116
116
  table.join("\n")
@@ -11,8 +11,8 @@ module Faker
11
11
  def initialize(name: nil, email: nil)
12
12
  super()
13
13
 
14
- @name = name || "#{Name.first_name} #{Name.last_name}"
15
- @email = email || Internet.email(name: self.name)
14
+ @name = name || "#{Faker::Name.first_name} #{Faker::Name.last_name}"
15
+ @email = email || Faker::Internet.email(name: self.name)
16
16
  @first_name, @last_name = self.name.split
17
17
  end
18
18
 
@@ -27,8 +27,8 @@ module Faker
27
27
  # @return [Hash] An auth hash in the format provided by omniauth-google.
28
28
  #
29
29
  # @faker.version 1.8.0
30
- def google(name: nil, email: nil, uid: Number.number(digits: 9).to_s)
31
- auth = Omniauth.new(name: name, email: email)
30
+ def google(name: nil, email: nil, uid: Faker::Number.number(digits: 9).to_s)
31
+ auth = new(name: name, email: email)
32
32
  {
33
33
  provider: 'google_oauth2',
34
34
  uid: uid,
@@ -40,9 +40,9 @@ module Faker
40
40
  image: image
41
41
  },
42
42
  credentials: {
43
- token: Crypto.md5,
44
- refresh_token: Crypto.md5,
45
- expires_at: Time.forward.to_i,
43
+ token: Faker::Crypto.md5,
44
+ refresh_token: Faker::Crypto.md5,
45
+ expires_at: Faker::Time.forward.to_i,
46
46
  expires: true
47
47
  },
48
48
  extra: {
@@ -56,20 +56,20 @@ module Faker
56
56
  profile: "https://plus.google.com/#{uid}",
57
57
  picture: image,
58
58
  gender: gender,
59
- birthday: Date.backward(days: 36_400).strftime('%Y-%m-%d'),
59
+ birthday: Faker::Date.backward(days: 36_400).strftime('%Y-%m-%d'),
60
60
  locale: 'en',
61
- hd: "#{Company.name.downcase}.com"
61
+ hd: "#{Faker::Company.name.downcase}.com"
62
62
  },
63
63
  id_info: {
64
64
  iss: 'accounts.google.com',
65
- at_hash: Crypto.md5,
65
+ at_hash: Faker::Crypto.md5,
66
66
  email_verified: true,
67
- sub: Number.number(digits: 28).to_s,
67
+ sub: Faker::Number.number(digits: 28).to_s,
68
68
  azp: 'APP_ID',
69
69
  email: auth.email,
70
70
  aud: 'APP_ID',
71
- iat: Time.forward.to_i,
72
- exp: Time.forward.to_i,
71
+ iat: Faker::Time.forward.to_i,
72
+ exp: Faker::Time.forward.to_i,
73
73
  openid_id: "https://www.google.com/accounts/o8/id?id=#{uid}"
74
74
  }
75
75
  }
@@ -87,8 +87,8 @@ module Faker
87
87
  # @return [Hash] An auth hash in the format provided by omniauth-facebook.
88
88
  #
89
89
  # @faker.version 1.8.0
90
- def facebook(name: nil, email: nil, username: nil, uid: Number.number(digits: 7).to_s)
91
- auth = Omniauth.new(name: name, email: email)
90
+ def facebook(name: nil, email: nil, username: nil, uid: Faker::Number.number(digits: 7).to_s)
91
+ auth = new(name: name, email: email)
92
92
  username ||= "#{auth.first_name.downcase[0]}#{auth.last_name.downcase}"
93
93
  {
94
94
  provider: 'facebook',
@@ -102,7 +102,7 @@ module Faker
102
102
  verified: random_boolean
103
103
  },
104
104
  credentials: {
105
- token: Crypto.md5,
105
+ token: Faker::Crypto.md5,
106
106
  expires_at: Time.forward.to_i,
107
107
  expires: true
108
108
  },
@@ -115,7 +115,7 @@ module Faker
115
115
  link: "http://www.facebook.com/#{username}",
116
116
  username: username,
117
117
  location: {
118
- id: Number.number(digits: 9).to_s,
118
+ id: Faker::Number.number(digits: 9).to_s,
119
119
  name: city_state
120
120
  },
121
121
  gender: gender,
@@ -123,7 +123,7 @@ module Faker
123
123
  timezone: timezone,
124
124
  locale: 'en_US',
125
125
  verified: random_boolean,
126
- updated_time: Time.backward.iso8601
126
+ updated_time: Faker::Time.backward.iso8601
127
127
  }
128
128
  }
129
129
  }
@@ -139,11 +139,11 @@ module Faker
139
139
  # @return [Hash] An auth hash in the format provided by omniauth-twitter.
140
140
  #
141
141
  # @faker.version 1.8.0
142
- def twitter(name: nil, nickname: nil, uid: Number.number(digits: 6).to_s)
143
- auth = Omniauth.new(name: name)
142
+ def twitter(name: nil, nickname: nil, uid: Faker::Number.number(digits: 6).to_s)
143
+ auth = new(name: name)
144
144
  nickname ||= auth.name.downcase.delete(' ')
145
145
  location = city_state
146
- description = Lorem.sentence
146
+ description = Faker::Lorem.sentence
147
147
  {
148
148
  provider: 'twitter',
149
149
  uid: uid,
@@ -159,26 +159,26 @@ module Faker
159
159
  }
160
160
  },
161
161
  credentials: {
162
- token: Crypto.md5,
163
- secret: Crypto.md5
162
+ token: Faker::Crypto.md5,
163
+ secret: Faker::Crypto.md5
164
164
  },
165
165
  extra: {
166
166
  access_token: '',
167
167
  raw_info: {
168
168
  name: auth.name,
169
169
  listed_count: random_number_from_range(1..10),
170
- profile_sidebar_border_color: Color.hex_color,
170
+ profile_sidebar_border_color: Faker::Color.hex_color,
171
171
  url: nil,
172
172
  lang: 'en',
173
173
  statuses_count: random_number_from_range(1..1000),
174
174
  profile_image_url: image,
175
175
  profile_background_image_url_https: image,
176
176
  location: location,
177
- time_zone: Address.city,
177
+ time_zone: Faker::Address.city,
178
178
  follow_request_sent: random_boolean,
179
179
  id: uid,
180
180
  profile_background_tile: random_boolean,
181
- profile_sidebar_fill_color: Color.hex_color,
181
+ profile_sidebar_fill_color: Faker::Color.hex_color,
182
182
  followers_count: random_number_from_range(1..10_000),
183
183
  default_profile_image: random_boolean,
184
184
  screen_name: '',
@@ -186,7 +186,7 @@ module Faker
186
186
  utc_offset: timezone,
187
187
  verified: random_boolean,
188
188
  favourites_count: random_number_from_range(1..10),
189
- profile_background_color: Color.hex_color,
189
+ profile_background_color: Faker::Color.hex_color,
190
190
  is_translator: random_boolean,
191
191
  friends_count: random_number_from_range(1..10_000),
192
192
  notifications: random_boolean,
@@ -194,8 +194,8 @@ module Faker
194
194
  profile_background_image_url: image,
195
195
  protected: random_boolean,
196
196
  description: description,
197
- profile_link_color: Color.hex_color,
198
- created_at: Time.backward.strftime('%a %b %d %H:%M:%S %z %Y'),
197
+ profile_link_color: Faker::Color.hex_color,
198
+ created_at: Faker::Time.backward.strftime('%a %b %d %H:%M:%S %z %Y'),
199
199
  id_str: uid,
200
200
  profile_image_url_https: image,
201
201
  default_profile: random_boolean,
@@ -222,15 +222,15 @@ module Faker
222
222
  # @return [Hash] An auth hash in the format provided by omniauth-linkedin.
223
223
  #
224
224
  # @faker.version 1.8.0
225
- def linkedin(name: nil, email: nil, uid: Number.number(digits: 6).to_s)
225
+ def linkedin(name: nil, email: nil, uid: Faker::Number.number(digits: 6).to_s)
226
226
  auth = Omniauth.new(name: name, email: email)
227
227
  first_name = auth.first_name.downcase
228
228
  last_name = auth.last_name.downcase
229
229
  location = city_state
230
- description = Lorem.sentence
231
- token = Crypto.md5
232
- secret = Crypto.md5
233
- industry = Commerce.department
230
+ description = Faker::Lorem.sentence
231
+ token = Faker::Crypto.md5
232
+ secret = Faker::Crypto.md5
233
+ industry = Faker::Commerce.department
234
234
  url = "http://www.linkedin.com/in/#{first_name}#{last_name}"
235
235
  {
236
236
  provider: 'linkedin',
@@ -244,7 +244,7 @@ module Faker
244
244
  location: location,
245
245
  description: description,
246
246
  image: image,
247
- phone: PhoneNumber.phone_number,
247
+ phone: Faker::PhoneNumber.phone_number,
248
248
  headline: description,
249
249
  industry: industry,
250
250
  urls: {
@@ -275,7 +275,7 @@ module Faker
275
275
  industry: industry,
276
276
  lastName: auth.last_name,
277
277
  location: {
278
- country: { code: Address.country_code.downcase },
278
+ country: { code: Faker::Address.country_code.downcase },
279
279
  name: city_state.split(', ').first
280
280
  },
281
281
  pictureUrl: image,
@@ -295,8 +295,8 @@ module Faker
295
295
  # @return [Hash] An auth hash in the format provided by omniauth-github.
296
296
  #
297
297
  # @faker.version 1.8.0
298
- def github(name: nil, email: nil, uid: Number.number(digits: 8).to_s)
299
- auth = Omniauth.new(name: name, email: email)
298
+ def github(name: nil, email: nil, uid: Faker::Number.number(digits: 8).to_s)
299
+ auth = new(name: name, email: email)
300
300
  login = auth.name.downcase.tr(' ', '-')
301
301
  html_url = "https://github.com/#{login}"
302
302
  api_url = "https://api.github.com/users/#{login}"
@@ -346,8 +346,8 @@ module Faker
346
346
  public_gists: random_number_from_range(1..1000),
347
347
  followers: random_number_from_range(1..1000),
348
348
  following: random_number_from_range(1..1000),
349
- created_at: Time.backward(days: 36_400).iso8601,
350
- updated_at: Time.backward(days: 2).iso8601
349
+ created_at: Faker::Time.backward(days: 36_400).iso8601,
350
+ updated_at: Faker::Time.backward(days: 2).iso8601
351
351
  }
352
352
  }
353
353
  }
@@ -364,8 +364,8 @@ module Faker
364
364
  #
365
365
  # @faker.version 2.3.0
366
366
  def apple(name: nil, email: nil, uid: nil)
367
- uid ||= "#{Number.number(digits: 6)}.#{Number.hexadecimal(digits: 32)}.#{Number.number(digits: 4)}"
368
- auth = Omniauth.new(name: name, email: email)
367
+ uid ||= "#{Faker::Number.number(digits: 6)}.#{Faker::Number.hexadecimal(digits: 32)}.#{Faker::Number.number(digits: 4)}"
368
+ auth = new(name: name, email: email)
369
369
  {
370
370
  provider: 'apple',
371
371
  uid: uid,
@@ -376,20 +376,20 @@ module Faker
376
376
  last_name: auth.last_name
377
377
  },
378
378
  credentials: {
379
- token: Crypto.md5,
380
- refresh_token: Crypto.md5,
381
- expires_at: Time.forward.to_i,
379
+ token: Faker::Crypto.md5,
380
+ refresh_token: Faker::Crypto.md5,
381
+ expires_at: Faker::Time.forward.to_i,
382
382
  expires: true
383
383
  },
384
384
  extra: {
385
385
  raw_info: {
386
386
  iss: 'https://appleid.apple.com',
387
387
  aud: 'CLIENT_ID',
388
- exp: Time.forward.to_i,
389
- iat: Time.forward.to_i,
388
+ exp: Faker::Time.forward.to_i,
389
+ iat: Faker::Time.forward.to_i,
390
390
  sub: uid,
391
- at_hash: Crypto.md5,
392
- auth_time: Time.forward.to_i,
391
+ at_hash: Faker::Crypto.md5,
392
+ auth_time: Faker::Time.forward.to_i,
393
393
  email: auth.email,
394
394
  email_verified: true
395
395
  }
@@ -408,8 +408,8 @@ module Faker
408
408
  #
409
409
  # @faker.version next
410
410
  def auth0(name: nil, email: nil, uid: nil)
411
- uid ||= "auth0|#{Number.hexadecimal(digits: 24)}"
412
- auth = Omniauth.new(name: name, email: email)
411
+ uid ||= "auth0|#{Faker::Number.hexadecimal(digits: 24)}"
412
+ auth = new(name: name, email: email)
413
413
  {
414
414
  provider: 'auth0',
415
415
  uid: uid,
@@ -423,9 +423,9 @@ module Faker
423
423
  expires_at: Time.forward.to_i,
424
424
  expires: true,
425
425
  token_type: 'Bearer',
426
- id_token: Crypto.sha256,
427
- token: Crypto.md5,
428
- refresh_token: Crypto.md5
426
+ id_token: Faker::Crypto.sha256,
427
+ token: Faker::Crypto.md5,
428
+ refresh_token: Faker::Crypto.md5
429
429
  },
430
430
  extra: {
431
431
  raw_info: {
@@ -434,8 +434,8 @@ module Faker
434
434
  iss: 'https://auth0.com/',
435
435
  sub: uid,
436
436
  aud: 'Auth012345',
437
- iat: Time.forward.to_i,
438
- exp: Time.forward.to_i
437
+ iat: Faker::Time.forward.to_i,
438
+ exp: Faker::Time.forward.to_i
439
439
  }
440
440
  }
441
441
  }
@@ -452,11 +452,11 @@ module Faker
452
452
  end
453
453
 
454
454
  def image
455
- Placeholdit.image
455
+ Faker::Placeholdit.image
456
456
  end
457
457
 
458
458
  def city_state
459
- "#{Address.city}, #{Address.state}"
459
+ "#{Faker::Address.city}, #{Faker::Address.state}"
460
460
  end
461
461
 
462
462
  def random_number_from_range(range)
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ class Default
5
+ if Faker::Config.lazy_loading?
6
+ Faker.lazy_load(self)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ class Fantasy
5
+ if Faker::Config.lazy_loading?
6
+ Faker.lazy_load(self)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ class Games
5
+ if Faker::Config.lazy_loading?
6
+ Faker.lazy_load(self)
7
+ end
8
+ end
9
+ end
@@ -2,6 +2,10 @@
2
2
 
3
3
  module Faker
4
4
  class Internet < Base
5
+ if Faker::Config.lazy_loading?
6
+ Faker.lazy_load(self)
7
+ end
8
+
5
9
  # Private, Host, and Link-Local network address blocks as defined in https://en.wikipedia.org/wiki/IPv4#Special-use_addresses
6
10
  PRIVATE_IPV4_ADDRESS_RANGES = [
7
11
  [10..10, 0..255, 0..255, 1..255], # 10.0.0.0/8 - Used for local communications within a private network
@@ -93,8 +97,8 @@ module Faker
93
97
  end
94
98
 
95
99
  sample([
96
- Char.prepare(Name.first_name),
97
- [Name.first_name, Name.last_name].map do |name|
100
+ Char.prepare(Faker::Name.first_name),
101
+ [Faker::Name.first_name, Faker::Name.last_name].map do |name|
98
102
  Char.prepare(name)
99
103
  end.join(sample(separators))
100
104
  ])
@@ -235,7 +239,7 @@ module Faker
235
239
  # @example
236
240
  # Faker::Internet.domain_word #=> "senger"
237
241
  def domain_word
238
- with_locale(:en) { Char.prepare(Company.name.split.first) }
242
+ with_locale(:en) { Char.prepare(Faker::Company.name.split.first) }
239
243
  end
240
244
 
241
245
  ## Returns the domain suffix e.g. com, org, co, biz, info etc.
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ class JapaneseMedia
5
+ if Faker::Config.lazy_loading?
6
+ Faker.lazy_load(self)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ class Locations
5
+ if Faker::Config.lazy_loading?
6
+ Faker.lazy_load(self)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ class Movies
5
+ if Faker::Config.lazy_loading?
6
+ Faker.lazy_load(self)
7
+ end
8
+ end
9
+ end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'music'
4
-
5
3
  module Faker
6
4
  class Music
7
5
  class BossaNova < Base
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'music'
4
-
5
3
  module Faker
6
4
  class Music
7
5
  class GratefulDead < Base
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'music'
4
-
5
3
  module Faker
6
4
  class Music
7
5
  class PearlJam < Base
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'music'
4
-
5
3
  module Faker
6
4
  class Music
7
5
  class Rush < Base
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'music'
4
-
5
3
  module Faker
6
4
  class Music
7
5
  class SmashingPumpkins < Base
@@ -2,6 +2,10 @@
2
2
 
3
3
  module Faker
4
4
  class Music < Base
5
+ if Faker::Config.lazy_loading?
6
+ Faker.lazy_load(self)
7
+ end
8
+
5
9
  class << self
6
10
  NOTE_LETTERS = %w[C D E F G A B].freeze
7
11
  ACCIDENTAL_SIGNS = ['b', '#', ''].freeze
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ class Quotes
5
+ if Faker::Config.lazy_loading?
6
+ Faker.lazy_load(self)
7
+ end
8
+ end
9
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Faker
4
- module Religion
4
+ class Religion
5
5
  class Bible < Base
6
6
  flexible :bible
7
7
 
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ class Religion
5
+ if Faker::Config.lazy_loading?
6
+ Faker.lazy_load(self)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ class Sports
5
+ if Faker::Config.lazy_loading?
6
+ Faker.lazy_load(self)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ class Travel
5
+ if Faker::Config.lazy_loading?
6
+ Faker.lazy_load(self)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faker
4
+ class TvShows
5
+ if Faker::Config.lazy_loading?
6
+ Faker.lazy_load(self)
7
+ end
8
+ end
9
+ end
data/lib/faker/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Faker # :nodoc:
4
- VERSION = '3.7.1'
4
+ VERSION = '3.8.0'
5
5
  end
data/lib/faker.rb CHANGED
@@ -38,6 +38,18 @@ module Faker
38
38
  def random
39
39
  Thread.current[:faker_config_random] || Random
40
40
  end
41
+
42
+ def lazy_loading?
43
+ if ENV.key?('FAKER_LAZY_LOAD') && !ENV['FAKER_LAZY_LOAD'].nil?
44
+ %w[true TRUE 1].include?(ENV.fetch('FAKER_LAZY_LOAD', nil))
45
+ else
46
+ Thread.current[:faker_lazy_loading] == true
47
+ end
48
+ end
49
+
50
+ def lazy_loading=(value)
51
+ Thread.current[:faker_lazy_loading] = value
52
+ end
41
53
  end
42
54
  end
43
55
 
@@ -275,7 +287,47 @@ module Faker
275
287
  end
276
288
  end
277
289
  end
290
+
291
+ if Faker::Config.lazy_loading?
292
+ def self.load_path(*constants)
293
+ constants.map do |class_name|
294
+ class_name
295
+ .to_s
296
+ .gsub('::', '/')
297
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
298
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
299
+ .tr('-', '_')
300
+ .downcase
301
+ end.join('/')
302
+ end
303
+
304
+ def self.lazy_load(klass)
305
+ def klass.const_missing(class_name)
306
+ load_path = case class_name
307
+ when :DnD
308
+ Faker.load_path('faker/games/dnd')
309
+ else
310
+ Faker.load_path(name, class_name)
311
+ end
312
+
313
+ begin
314
+ require(load_path)
315
+ rescue LoadError
316
+ require(load_path.gsub('faker/', 'faker/default/'))
317
+ end
318
+
319
+ const_get(class_name)
320
+ end
321
+ end
322
+
323
+ lazy_load(self)
324
+ end
278
325
  end
279
326
 
280
- # require faker objects
281
- Dir.glob(File.join(mydir, 'faker', '/**/*.rb')).each { |file| require file }
327
+ unless Faker::Config.lazy_loading?
328
+ rb_files = []
329
+ rb_files << File.join(mydir, 'faker', '*.rb')
330
+ rb_files << File.join(mydir, 'faker', '/**/*.rb')
331
+
332
+ Dir.glob(rb_files).each { |file| require file }
333
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faker
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.1
4
+ version: 3.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Curtis
@@ -45,20 +45,23 @@ files:
45
45
  - README.md
46
46
  - bin/faker
47
47
  - lib/faker.rb
48
+ - lib/faker/blockchain.rb
48
49
  - lib/faker/blockchain/aeternity.rb
49
50
  - lib/faker/blockchain/bitcoin.rb
50
51
  - lib/faker/blockchain/ethereum.rb
51
52
  - lib/faker/blockchain/tezos.rb
52
- - lib/faker/books/book.rb
53
+ - lib/faker/books.rb
53
54
  - lib/faker/books/culture_series.rb
54
55
  - lib/faker/books/dune.rb
55
56
  - lib/faker/books/lovecraft.rb
56
57
  - lib/faker/books/the_kingkiller_chronicle.rb
58
+ - lib/faker/creature.rb
57
59
  - lib/faker/creature/animal.rb
58
60
  - lib/faker/creature/bird.rb
59
61
  - lib/faker/creature/cat.rb
60
62
  - lib/faker/creature/dog.rb
61
63
  - lib/faker/creature/horse.rb
64
+ - lib/faker/default.rb
62
65
  - lib/faker/default/address.rb
63
66
  - lib/faker/default/adjective.rb
64
67
  - lib/faker/default/alphanumeric.rb
@@ -71,6 +74,7 @@ files:
71
74
  - lib/faker/default/barcode.rb
72
75
  - lib/faker/default/beer.rb
73
76
  - lib/faker/default/blood.rb
77
+ - lib/faker/default/book.rb
74
78
  - lib/faker/default/boolean.rb
75
79
  - lib/faker/default/business.rb
76
80
  - lib/faker/default/camera.rb
@@ -105,6 +109,7 @@ files:
105
109
  - lib/faker/default/finance.rb
106
110
  - lib/faker/default/food.rb
107
111
  - lib/faker/default/funny_name.rb
112
+ - lib/faker/default/game.rb
108
113
  - lib/faker/default/gender.rb
109
114
  - lib/faker/default/greek_philosophers.rb
110
115
  - lib/faker/default/hacker.rb
@@ -114,8 +119,6 @@ files:
114
119
  - lib/faker/default/html.rb
115
120
  - lib/faker/default/id_number.rb
116
121
  - lib/faker/default/industry_segments.rb
117
- - lib/faker/default/internet.rb
118
- - lib/faker/default/internet_http.rb
119
122
  - lib/faker/default/invoice.rb
120
123
  - lib/faker/default/job.rb
121
124
  - lib/faker/default/json.rb
@@ -127,6 +130,7 @@ files:
127
130
  - lib/faker/default/measurement.rb
128
131
  - lib/faker/default/military.rb
129
132
  - lib/faker/default/mountain.rb
133
+ - lib/faker/default/movie.rb
130
134
  - lib/faker/default/name.rb
131
135
  - lib/faker/default/nation.rb
132
136
  - lib/faker/default/national_health_service.rb
@@ -136,14 +140,15 @@ files:
136
140
  - lib/faker/default/phone_number.rb
137
141
  - lib/faker/default/placeholdit.rb
138
142
  - lib/faker/default/programming_language.rb
143
+ - lib/faker/default/quote.rb
139
144
  - lib/faker/default/relationship.rb
140
- - lib/faker/default/religion.rb
141
145
  - lib/faker/default/restaurant.rb
142
146
  - lib/faker/default/science.rb
143
147
  - lib/faker/default/slack_emoji.rb
144
148
  - lib/faker/default/source.rb
145
149
  - lib/faker/default/south_africa.rb
146
150
  - lib/faker/default/space.rb
151
+ - lib/faker/default/sport.rb
147
152
  - lib/faker/default/string.rb
148
153
  - lib/faker/default/stripe.rb
149
154
  - lib/faker/default/subscription.rb
@@ -159,7 +164,9 @@ files:
159
164
  - lib/faker/default/vulnerability_identifier.rb
160
165
  - lib/faker/default/world_cup.rb
161
166
  - lib/faker/default/x.rb
167
+ - lib/faker/fantasy.rb
162
168
  - lib/faker/fantasy/tolkien.rb
169
+ - lib/faker/games.rb
163
170
  - lib/faker/games/clash_of_clans.rb
164
171
  - lib/faker/games/control.rb
165
172
  - lib/faker/games/dnd.rb
@@ -167,7 +174,6 @@ files:
167
174
  - lib/faker/games/elder_scrolls.rb
168
175
  - lib/faker/games/fallout.rb
169
176
  - lib/faker/games/final_fantasy_xiv.rb
170
- - lib/faker/games/game.rb
171
177
  - lib/faker/games/half_life.rb
172
178
  - lib/faker/games/heroes.rb
173
179
  - lib/faker/games/heroes_of_the_storm.rb
@@ -186,6 +192,9 @@ files:
186
192
  - lib/faker/games/witcher.rb
187
193
  - lib/faker/games/world_of_warcraft.rb
188
194
  - lib/faker/games/zelda.rb
195
+ - lib/faker/internet.rb
196
+ - lib/faker/internet/http.rb
197
+ - lib/faker/japanese_media.rb
189
198
  - lib/faker/japanese_media/conan.rb
190
199
  - lib/faker/japanese_media/cowboy_bebop.rb
191
200
  - lib/faker/japanese_media/doraemon.rb
@@ -196,7 +205,9 @@ files:
196
205
  - lib/faker/japanese_media/one_piece.rb
197
206
  - lib/faker/japanese_media/studio_ghibli.rb
198
207
  - lib/faker/japanese_media/sword_art_online.rb
208
+ - lib/faker/locations.rb
199
209
  - lib/faker/locations/australia.rb
210
+ - lib/faker/movies.rb
200
211
  - lib/faker/movies/avatar.rb
201
212
  - lib/faker/movies/back_to_the_future.rb
202
213
  - lib/faker/movies/departed.rb
@@ -208,16 +219,15 @@ files:
208
219
  - lib/faker/movies/how_to_train_your_dragon.rb
209
220
  - lib/faker/movies/lebowski.rb
210
221
  - lib/faker/movies/lord_of_the_rings.rb
211
- - lib/faker/movies/movie.rb
212
222
  - lib/faker/movies/princess_bride.rb
213
223
  - lib/faker/movies/star_wars.rb
214
224
  - lib/faker/movies/the_room.rb
215
225
  - lib/faker/movies/tron.rb
216
226
  - lib/faker/movies/v_for_vendetta.rb
227
+ - lib/faker/music.rb
217
228
  - lib/faker/music/bossa_nova.rb
218
229
  - lib/faker/music/grateful_dead.rb
219
230
  - lib/faker/music/hiphop.rb
220
- - lib/faker/music/music.rb
221
231
  - lib/faker/music/opera.rb
222
232
  - lib/faker/music/pearl_jam.rb
223
233
  - lib/faker/music/phish.rb
@@ -226,19 +236,22 @@ files:
226
236
  - lib/faker/music/rush.rb
227
237
  - lib/faker/music/smashing_pumpkins.rb
228
238
  - lib/faker/music/umphreys_mcgee.rb
239
+ - lib/faker/quotes.rb
229
240
  - lib/faker/quotes/chiquito.rb
230
- - lib/faker/quotes/quote.rb
231
241
  - lib/faker/quotes/rajnikanth.rb
232
242
  - lib/faker/quotes/shakespeare.rb
243
+ - lib/faker/religion.rb
233
244
  - lib/faker/religion/bible.rb
245
+ - lib/faker/sports.rb
234
246
  - lib/faker/sports/basketball.rb
235
247
  - lib/faker/sports/chess.rb
236
248
  - lib/faker/sports/football.rb
237
249
  - lib/faker/sports/mountaineering.rb
238
- - lib/faker/sports/sport.rb
239
250
  - lib/faker/sports/volleyball.rb
251
+ - lib/faker/travel.rb
240
252
  - lib/faker/travel/airport.rb
241
253
  - lib/faker/travel/train_station.rb
254
+ - lib/faker/tv_shows.rb
242
255
  - lib/faker/tv_shows/aqua_teen_hunger_force.rb
243
256
  - lib/faker/tv_shows/archer.rb
244
257
  - lib/faker/tv_shows/big_bang_theory.rb
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Faker
4
- module Religion
5
- end
6
- end
File without changes
File without changes
File without changes
File without changes
File without changes