faker 3.6.0 → 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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +87 -0
  3. data/README.md +1 -2
  4. data/lib/faker/blockchain.rb +9 -0
  5. data/lib/faker/books.rb +9 -0
  6. data/lib/faker/creature.rb +9 -0
  7. data/lib/faker/default/driving_licence.rb +2 -2
  8. data/lib/faker/default/html.rb +3 -3
  9. data/lib/faker/default/id_number.rb +1 -1
  10. data/lib/faker/default/lorem.rb +2 -2
  11. data/lib/faker/default/markdown.rb +3 -3
  12. data/lib/faker/default/omniauth.rb +58 -58
  13. data/lib/faker/default/string.rb +1 -1
  14. data/lib/faker/default.rb +9 -0
  15. data/lib/faker/fantasy.rb +9 -0
  16. data/lib/faker/games.rb +9 -0
  17. data/lib/faker/{default/internet.rb → internet.rb} +7 -3
  18. data/lib/faker/japanese_media.rb +9 -0
  19. data/lib/faker/locations.rb +9 -0
  20. data/lib/faker/movies.rb +9 -0
  21. data/lib/faker/music/bossa_nova.rb +0 -2
  22. data/lib/faker/music/grateful_dead.rb +0 -2
  23. data/lib/faker/music/pearl_jam.rb +0 -2
  24. data/lib/faker/music/rush.rb +0 -2
  25. data/lib/faker/music/smashing_pumpkins.rb +0 -2
  26. data/lib/faker/{music/music.rb → music.rb} +4 -0
  27. data/lib/faker/quotes.rb +9 -0
  28. data/lib/faker/religion/bible.rb +1 -1
  29. data/lib/faker/religion.rb +9 -0
  30. data/lib/faker/sports.rb +9 -0
  31. data/lib/faker/travel.rb +9 -0
  32. data/lib/faker/tv_shows.rb +9 -0
  33. data/lib/faker/version.rb +1 -1
  34. data/lib/faker.rb +62 -9
  35. data/lib/helpers/positional_generator.rb +0 -2
  36. data/lib/helpers/unique_generator.rb +1 -1
  37. data/lib/locales/README.md +2 -2
  38. data/lib/locales/en/book.yml +0 -1
  39. data/lib/locales/en/football.yml +9 -0
  40. data/lib/locales/ja/address.yml +1 -120285
  41. metadata +25 -12
  42. data/lib/faker/default/religion.rb +0 -6
  43. /data/lib/faker/{books → default}/book.rb +0 -0
  44. /data/lib/faker/{games → default}/game.rb +0 -0
  45. /data/lib/faker/{movies → default}/movie.rb +0 -0
  46. /data/lib/faker/{quotes → default}/quote.rb +0 -0
  47. /data/lib/faker/{sports → default}/sport.rb +0 -0
  48. /data/lib/faker/{default/internet_http.rb → internet/http.rb} +0 -0
@@ -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.6.0'
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
 
@@ -95,12 +107,12 @@ module Faker
95
107
  reg
96
108
  .gsub(%r{^/?\^?}, '').gsub(%r{\$?/?$}, '') # Ditch the anchors
97
109
  .gsub(/\{(\d+)\}/, '{\1,\1}').gsub('?', '{0,1}') # All {2} become {2,2} and ? become {0,1}
98
- .gsub(/(\[[^\]]+\])\{(\d+),(\d+)\}/) { |_match| Regexp.last_match(1) * sample(Array(Range.new(Regexp.last_match(2).to_i, Regexp.last_match(3).to_i))) } # [12]{1,2} becomes [12] or [12][12]
99
- .gsub(/(\([^)]+\))\{(\d+),(\d+)\}/) { |_match| Regexp.last_match(1) * sample(Array(Range.new(Regexp.last_match(2).to_i, Regexp.last_match(3).to_i))) } # (12|34){1,2} becomes (12|34) or (12|34)(12|34)
100
- .gsub(/(\\?.)\{(\d+),(\d+)\}/) { |_match| Regexp.last_match(1) * sample(Array(Range.new(Regexp.last_match(2).to_i, Regexp.last_match(3).to_i))) } # A{1,2} becomes A or AA or \d{3} becomes \d\d\d
101
- .gsub(/\((.*?)\)/) { |match| sample(match.gsub(/[()]/, '').split('|')) } # (this|that) becomes 'this' or 'that'
102
- .gsub(/\[([^\]]+)\]/) { |match| match.gsub(/(\w-\w)/) { |range| sample(Array(Range.new(*range.split('-')))) } } # All A-Z inside of [] become C (or X, or whatever)
103
- .gsub(/\[([^\]]+)\]/) { |_match| sample(Regexp.last_match(1).chars) } # All [ABC] become B (or A or C)
110
+ .gsub(/(\[[^\]]++\])\{(\d+),(\d+)\}/) { |_match| Regexp.last_match(1) * sample(Array(Range.new(Regexp.last_match(2).to_i, Regexp.last_match(3).to_i))) } # [12]{1,2} becomes [12] or [12][12]
111
+ .gsub(/(\([^)]++\))\{(\d+),(\d+)\}/) { |_match| Regexp.last_match(1) * sample(Array(Range.new(Regexp.last_match(2).to_i, Regexp.last_match(3).to_i))) } # (12|34){1,2} becomes (12|34) or (12|34)(12|34)
112
+ .gsub(/(\\?.)\{(\d+),(\d+)\}/) { |_match| Regexp.last_match(1) * sample(Array(Range.new(Regexp.last_match(2).to_i, Regexp.last_match(3).to_i))) } # A{1,2} becomes A or AA or \d{3} becomes \d\d\d
113
+ .gsub(/\((.*?)\)/) { |match| sample(match.gsub(/[()]/, '').split('|')) } # (this|that) becomes 'this' or 'that'
114
+ .gsub(/\[([^\]]++)\]/) { |match| match.gsub(/(\w-\w)/) { |range| sample(Array(Range.new(*range.split('-')))) } } # All A-Z inside of [] become C (or X, or whatever)
115
+ .gsub(/\[([^\]]++)\]/) { |_match| sample(Regexp.last_match(1).chars) } # All [ABC] become B (or A or C)
104
116
  .gsub('\d') { |_match| sample(Numbers) }
105
117
  .gsub('\w') { |_match| sample(Letters) }
106
118
  end
@@ -133,7 +145,8 @@ module Faker
133
145
  # formatted translation: e.g., "#{first_name} #{last_name}".
134
146
  def parse(key)
135
147
  fetched = fetch(key)
136
- parts = fetched.scan(/(\(?)#\{([A-Za-z]+\.)?([^}]+)\}([^#]+)?/).map do |prefix, kls, meth, etc|
148
+
149
+ parts = fetched.scan(/(\(?)#\{([A-Za-z]+\.)?([^}]+)\}([^#]++)?/).map do |prefix, kls, meth, etc|
137
150
  # If the token had a class Prefix (e.g., Name.first_name)
138
151
  # grab the constant, otherwise use self
139
152
  cls = kls ? Faker.const_get(kls.chop) : self
@@ -274,7 +287,47 @@ module Faker
274
287
  end
275
288
  end
276
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
277
325
  end
278
326
 
279
- # require faker objects
280
- 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
@@ -278,8 +278,6 @@ class PositionalGenerator
278
278
  # [2]
279
279
  # ]
280
280
  def build_stack(graph)
281
- require 'set'
282
-
283
281
  terminals = graph.filter_map { |(from, to)| to.nil? && from }
284
282
  stack = [terminals]
285
283
  seen = Set.new(terminals)
@@ -30,7 +30,7 @@ module Faker
30
30
  method_name.to_s.start_with?('faker_') || super
31
31
  end
32
32
 
33
- RetryLimitExceeded = Class.new(StandardError)
33
+ class RetryLimitExceeded < StandardError; end
34
34
 
35
35
  def previous_results
36
36
  Thread.current[:faker_unique_generator_previous_results] ||= {}
@@ -20,7 +20,7 @@ Faker::Hipster.word #=> "kogi"
20
20
 
21
21
  ## How to update a locale with more translations
22
22
 
23
- To update a locale with more translation features, simply add a new field to the .yml file that corresponds to an existing piece of functionality in the "en.yml" file. In this example, that would mean providing Chinese hipster words.
23
+ To update a locale with more translation features, simply add a new field to the `.yml` file that corresponds to an existing piece of functionality in the "en.yml" file. In this example, that would mean providing Chinese hipster words.
24
24
 
25
25
  ```yaml
26
26
  # /lib/locales/zh-CN.yml
@@ -52,5 +52,5 @@ Faker::Config.default_locale = :pt
52
52
  In threaded server environments, e.g., Puma, locale per thread can be set as the following:
53
53
 
54
54
  ```ruby
55
- Faker::Config.locale = :es
55
+ Faker::Config.locale = :es
56
56
  ```
@@ -139,7 +139,6 @@ en:
139
139
  - The Proper Study
140
140
  - Quo Vadis
141
141
  - Recalled to Life
142
- - Recalled to Life
143
142
  - Ring of Bright Water
144
143
  - The Road Less Traveled
145
144
  - A Scanner Darkly
@@ -23,6 +23,15 @@ en:
23
23
  - PSV Eindhoven
24
24
  - LA Galaxy
25
25
  - Paris Saint Germain
26
+ - FC Porto
27
+ - Manchester City
28
+ - Sporting
29
+ - Atalanta
30
+ - Villareal
31
+ - Lyon
32
+ - AS Monaco
33
+ - Bayer 04 Leverkusen
34
+ - Aston Villa
26
35
  players:
27
36
  - Lionel Messi
28
37
  - Gerard Pique