faker 3.2.0 → 3.5.2
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 +437 -2
- data/README.md +29 -14
- data/lib/faker/books/lovecraft.rb +2 -3
- data/lib/faker/default/address.rb +2 -2
- data/lib/faker/default/alphanumeric.rb +1 -1
- data/lib/faker/default/chile_rut.rb +23 -17
- data/lib/faker/default/code.rb +64 -18
- data/lib/faker/default/company.rb +99 -5
- data/lib/faker/default/crypto.rb +13 -4
- data/lib/faker/default/date.rb +61 -5
- data/lib/faker/default/driving_licence.rb +19 -8
- data/lib/faker/default/finance.rb +2 -2
- data/lib/faker/default/hipster.rb +2 -3
- data/lib/faker/default/html.rb +230 -0
- data/lib/faker/default/id_number.rb +38 -24
- data/lib/faker/default/internet.rb +19 -53
- data/lib/faker/default/invoice.rb +3 -3
- data/lib/faker/default/json.rb +9 -4
- data/lib/faker/default/lorem.rb +6 -3
- data/lib/faker/default/{nhs.rb → national_health_service.rb} +8 -4
- data/lib/faker/default/number.rb +1 -1
- data/lib/faker/default/omniauth.rb +4 -4
- data/lib/faker/default/phone_number.rb +37 -18
- data/lib/faker/default/placeholdit.rb +1 -1
- data/lib/faker/default/south_africa.rb +3 -3
- data/lib/faker/{music/show.rb → default/theater.rb} +8 -8
- data/lib/faker/default/types.rb +5 -6
- data/lib/faker/default/vehicle.rb +23 -11
- data/lib/faker/games/final_fantasy_xiv.rb +73 -0
- data/lib/faker/games/heroes_of_the_storm.rb +0 -11
- data/lib/faker/japanese_media/fullmetal_alchemist_brotherhood.rb +10 -10
- data/lib/faker/locations/australia.rb +40 -38
- data/lib/faker/movies/star_wars.rb +1 -1
- data/lib/faker/movies/{room.rb → the_room.rb} +4 -4
- data/lib/faker/music/smashing_pumpkins.rb +64 -0
- data/lib/faker/travel/airport.rb +2 -2
- data/lib/faker/travel/train_station.rb +54 -0
- data/lib/faker/tv_shows/archer.rb +51 -0
- data/lib/faker/tv_shows/buffy.rb +0 -13
- data/lib/faker/tv_shows/dr_who.rb +0 -13
- data/lib/faker/tv_shows/south_park.rb +15 -0
- data/lib/faker/tv_shows/the_fresh_prince_of_bel_air.rb +0 -13
- data/lib/faker/version.rb +1 -1
- data/lib/faker.rb +20 -8
- data/lib/helpers/deprecator.rb +118 -0
- data/lib/helpers/positional_generator.rb +480 -0
- data/lib/locales/README.md +18 -2
- data/lib/locales/bg.yml +0 -1
- data/lib/locales/da-DK.yml +529 -35
- data/lib/locales/de-AT.yml +3487 -26
- data/lib/locales/de-CH.yml +4359 -12
- data/lib/locales/de.yml +7182 -100
- data/lib/locales/ee.yml +0 -1
- data/lib/locales/en/address.yml +1826 -561
- data/lib/locales/en/archer.yml +75 -0
- data/lib/locales/en/australia.yml +106 -105
- data/lib/locales/en/bank.yml +1 -1
- data/lib/locales/en/cosmere.yml +1 -1
- data/lib/locales/en/dog.yml +262 -7
- data/lib/locales/en/dota.yml +120 -67
- data/lib/locales/en/final_fantasy_xiv.yml +754 -0
- data/lib/locales/en/finance.yml +4 -4
- data/lib/locales/en/food.yml +2 -1
- data/lib/locales/en/{fma_brotherhood.yml → fullmetal_alchemist_brotherhood.yml} +3 -3
- data/lib/locales/en/harry_potter.yml +1 -1
- data/lib/locales/en/id_number.yml +1 -1
- data/lib/locales/en/internet.yml +0 -4
- data/lib/locales/en/minecraft.yml +4 -4
- data/lib/locales/en/music.yml +25 -25
- data/lib/locales/en/opera.yml +1 -1
- data/lib/locales/en/phone_number.yml +78 -3
- data/lib/locales/en/restaurant.yml +1 -1
- data/lib/locales/en/smashing_pumpkins.yml +382 -0
- data/lib/locales/en/south_park.yml +360 -2
- data/lib/locales/en/{room.yml → the_room.yml} +1 -1
- data/lib/locales/en/{show.yml → theater.yml} +1 -1
- data/lib/locales/en/train_station.yml +280 -0
- data/lib/locales/en/vehicle.yml +1 -1
- data/lib/locales/en-AU.yml +718 -47
- data/lib/locales/en-CA.yml +373 -19
- data/lib/locales/en-GB.yml +116 -9
- data/lib/locales/en-IND.yml +1259 -17
- data/lib/locales/en-KE.yml +212 -0
- data/lib/locales/en-MS.yml +364 -18
- data/lib/locales/en-NEP.yml +212 -38
- data/lib/locales/en-NZ.yml +1153 -124
- data/lib/locales/en-PAK.yml +392 -11
- data/lib/locales/en-SG.yml +581 -17
- data/lib/locales/en-US.yml +6914 -74
- data/lib/locales/en-au-ocker.yml +266 -24
- data/lib/locales/es-AR.yml +4569 -4600
- data/lib/locales/es-MX.yml +0 -1
- data/lib/locales/es.yml +0 -1
- data/lib/locales/fr/address.yml +761 -8
- data/lib/locales/fr/internet.yml +0 -1
- data/lib/locales/fr/name.yml +2 -1
- data/lib/locales/fr-CA.yml +2733 -44
- data/lib/locales/fr-CH.yml +0 -1
- data/lib/locales/fr.yml +3 -1
- data/lib/locales/hy.yml +3624 -120
- data/lib/locales/id.yml +839 -12
- data/lib/locales/it.yml +1304 -33
- data/lib/locales/ja/book.yml +492 -3
- data/lib/locales/ja/football.yml +115 -0
- data/lib/locales/ja/lorem.yml +1 -1
- data/lib/locales/ja/sport.yml +130 -0
- data/lib/locales/ja/touhou.yml +466 -0
- data/lib/locales/ko.yml +1361 -21
- data/lib/locales/lt.yml +297 -16
- data/lib/locales/lv.yml +0 -1
- data/lib/locales/nb-NO.yml +518 -30
- data/lib/locales/nl.yml +9 -2
- data/lib/locales/pl.yml +0 -1
- data/lib/locales/pt-BR.yml +8205 -665
- data/lib/locales/pt.yml +844 -45
- data/lib/locales/ru.yml +1353 -70
- data/lib/locales/sk.yml +4410 -44
- data/lib/locales/sv.yml +99 -0
- data/lib/locales/tr.yml +0 -2
- data/lib/locales/uk.yml +1808 -45
- data/lib/locales/zh-CN/bank.yml +17 -0
- metadata +26 -154
- data/History.md +0 -176
data/lib/faker/travel/airport.rb
CHANGED
@@ -11,7 +11,7 @@ module Faker
|
|
11
11
|
#
|
12
12
|
# @param region [String] airport region, currently available -> united_states or european_union
|
13
13
|
#
|
14
|
-
# @
|
14
|
+
# @return [String]
|
15
15
|
#
|
16
16
|
# @example
|
17
17
|
# Faker::Travel::Airport.name(size: 'large', region: 'united_states') => "Los Angeles International Airport"
|
@@ -28,7 +28,7 @@ module Faker
|
|
28
28
|
#
|
29
29
|
# @param region [String] airport region, currently available -> united_states or european_union
|
30
30
|
#
|
31
|
-
# @
|
31
|
+
# @return [String]
|
32
32
|
#
|
33
33
|
# @example
|
34
34
|
# Faker::Travel::Airport.iata(size: 'large', region: 'united_states') => "LAX"
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Faker
|
4
|
+
class Travel
|
5
|
+
class TrainStation < Base
|
6
|
+
class << self
|
7
|
+
##
|
8
|
+
# Produces random Train Station by name and takes optional arguments for region and type
|
9
|
+
#
|
10
|
+
# @param region [String] Train station region: germany, spain, united_kingdom, united_states
|
11
|
+
#
|
12
|
+
# @param type [String] Train station type: metro, railway
|
13
|
+
#
|
14
|
+
# @return [String]
|
15
|
+
#
|
16
|
+
# @examples
|
17
|
+
# Faker::Travel::TrainStation.name(region: 'united_kingdom', type: 'metro') => "Brockley"
|
18
|
+
# Faker::Travel::TrainStation.name(type: 'railway') => "Düsseldorf Hauptbahnhof"
|
19
|
+
# Faker::Travel::TrainStation.name(region: 'spain') => "Santa Eulàlia"
|
20
|
+
#
|
21
|
+
# @faker.version next
|
22
|
+
def name(region: nil, type: nil)
|
23
|
+
region, type = fill_missing_inputs_with_samples(region, type)
|
24
|
+
fetch("train_station.#{region}.#{type}")
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def fill_missing_inputs_with_samples(region, type)
|
30
|
+
regions = %w[germany spain united_kingdom united_states]
|
31
|
+
types = %w[metro railway]
|
32
|
+
|
33
|
+
if region.nil? && type.nil?
|
34
|
+
region = sample(regions)
|
35
|
+
type = sample(types)
|
36
|
+
elsif region.nil?
|
37
|
+
validate_arguments(type, types, 'type')
|
38
|
+
region = sample(regions)
|
39
|
+
elsif type.nil?
|
40
|
+
validate_arguments(region, regions, 'region')
|
41
|
+
type = sample(types)
|
42
|
+
end
|
43
|
+
[region, type]
|
44
|
+
end
|
45
|
+
|
46
|
+
def validate_arguments(argument, correct_values, argument_name)
|
47
|
+
return if correct_values.include?(argument)
|
48
|
+
|
49
|
+
raise ArgumentError, "'#{argument}' not found, #{argument_name} can be blank, or one of the following, as strings: #{correct_values.join(', ')}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Faker
|
4
|
+
class TvShows
|
5
|
+
class Archer < Base
|
6
|
+
flexible :archer
|
7
|
+
|
8
|
+
class << self
|
9
|
+
##
|
10
|
+
# Produces a character from Archer.
|
11
|
+
#
|
12
|
+
# @return [String]
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# Faker::TvShows::Archer.character #=> "Sterling Archer"
|
16
|
+
#
|
17
|
+
# @faker.version next
|
18
|
+
def character
|
19
|
+
fetch('archer.characters')
|
20
|
+
end
|
21
|
+
|
22
|
+
##
|
23
|
+
# Produces a location from Archer.
|
24
|
+
#
|
25
|
+
# @return [String]
|
26
|
+
#
|
27
|
+
# @example
|
28
|
+
# Faker::TvShows::Archer.location #=> "The Tuntmore Towers"
|
29
|
+
#
|
30
|
+
# @faker.version next
|
31
|
+
def location
|
32
|
+
fetch('archer.locations')
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Produces a quote from Archer.
|
37
|
+
#
|
38
|
+
# @return [String]
|
39
|
+
#
|
40
|
+
# @example
|
41
|
+
# Faker::TvShows::Archer.quote
|
42
|
+
# #=> "You're not my supervisor!"
|
43
|
+
#
|
44
|
+
# @faker.version next
|
45
|
+
def quote
|
46
|
+
fetch('archer.quotes')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/faker/tv_shows/buffy.rb
CHANGED
@@ -45,19 +45,6 @@ module Faker
|
|
45
45
|
fetch('buffy.actors')
|
46
46
|
end
|
47
47
|
|
48
|
-
##
|
49
|
-
# Produces a actor from Buffy the Vampire Slayer.
|
50
|
-
#
|
51
|
-
# @return [String]
|
52
|
-
#
|
53
|
-
# @example
|
54
|
-
# Faker::TvShows::Buffy.celebrity #=> "John Ritter"
|
55
|
-
#
|
56
|
-
# @deprecated Use the `actor` method instead.
|
57
|
-
#
|
58
|
-
# @faker.version 1.9.2
|
59
|
-
alias celebrity actor
|
60
|
-
|
61
48
|
##
|
62
49
|
# Produces a big bad from Buffy the Vampire Slayer.
|
63
50
|
#
|
@@ -84,19 +84,6 @@ module Faker
|
|
84
84
|
fetch('dr_who.villains')
|
85
85
|
end
|
86
86
|
|
87
|
-
##
|
88
|
-
# Produces a villain from Doctor Who.
|
89
|
-
#
|
90
|
-
# @return [String]
|
91
|
-
#
|
92
|
-
# @example
|
93
|
-
# Faker::TvShows::DrWho.villian #=> "The Master"
|
94
|
-
#
|
95
|
-
# @deprecated Use the correctly-spelled `villain` method instead.
|
96
|
-
#
|
97
|
-
# @faker.version 1.8.0
|
98
|
-
alias villian villain
|
99
|
-
|
100
87
|
##
|
101
88
|
# Produces a species from Doctor Who.
|
102
89
|
#
|
@@ -32,6 +32,21 @@ module Faker
|
|
32
32
|
def quote
|
33
33
|
fetch('south_park.quotes')
|
34
34
|
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Produces an episode name from South Park.
|
38
|
+
#
|
39
|
+
# @return [String]
|
40
|
+
#
|
41
|
+
# @example
|
42
|
+
# Faker::TvShows::SouthPark.episode_name
|
43
|
+
# #=> "Make Love, Not Warcraft"
|
44
|
+
#
|
45
|
+
# @faker.version next
|
46
|
+
|
47
|
+
def episode_name
|
48
|
+
fetch('south_park.episodes')
|
49
|
+
end
|
35
50
|
end
|
36
51
|
end
|
37
52
|
end
|
@@ -32,19 +32,6 @@ module Faker
|
|
32
32
|
fetch('the_fresh_prince_of_bel_air.actors')
|
33
33
|
end
|
34
34
|
|
35
|
-
##
|
36
|
-
# Produces a actor from The Fresh Prince of Bel-Air.
|
37
|
-
#
|
38
|
-
# @return [String]
|
39
|
-
#
|
40
|
-
# @example
|
41
|
-
# Faker::TvShows::TheFreshPrinceOfBelAir.celebrity #=> "Quincy Jones"
|
42
|
-
#
|
43
|
-
# @deprecated Use the `actor` method instead.
|
44
|
-
#
|
45
|
-
# @faker.version 1.8.3
|
46
|
-
alias celebrity actor
|
47
|
-
|
48
35
|
##
|
49
36
|
# Produces a quote from The Fresh Prince of Bel-Air.
|
50
37
|
#
|
data/lib/faker/version.rb
CHANGED
data/lib/faker.rb
CHANGED
@@ -5,20 +5,24 @@ mydir = __dir__
|
|
5
5
|
require 'psych'
|
6
6
|
require 'i18n'
|
7
7
|
|
8
|
-
Dir.glob(File.join(mydir, 'helpers', '*.rb')).
|
8
|
+
Dir.glob(File.join(mydir, 'helpers', '*.rb')).each { |file| require file }
|
9
9
|
|
10
10
|
I18n.load_path += Dir[File.join(mydir, 'locales', '**/*.yml')]
|
11
11
|
|
12
12
|
module Faker
|
13
13
|
module Config
|
14
|
+
@default_locale = nil
|
15
|
+
|
14
16
|
class << self
|
17
|
+
attr_writer :default_locale
|
18
|
+
|
15
19
|
def locale=(new_locale)
|
16
20
|
Thread.current[:faker_config_locale] = new_locale
|
17
21
|
end
|
18
22
|
|
19
23
|
def locale
|
20
24
|
# Because I18n.locale defaults to :en, if we don't have :en in our available_locales, errors will happen
|
21
|
-
Thread.current[:faker_config_locale] || (I18n.available_locales.include?(I18n.locale) ? I18n.locale : I18n.available_locales.first)
|
25
|
+
Thread.current[:faker_config_locale] || @default_locale || (I18n.available_locales.include?(I18n.locale) ? I18n.locale : I18n.available_locales.first)
|
22
26
|
end
|
23
27
|
|
24
28
|
def own_locale
|
@@ -48,19 +52,23 @@ module Faker
|
|
48
52
|
|
49
53
|
## by default numerify results do not start with a zero
|
50
54
|
def numerify(number_string, leading_zero: false)
|
51
|
-
return number_string.gsub(
|
55
|
+
return number_string.gsub('#') { rand(10).to_s } if leading_zero
|
52
56
|
|
53
|
-
number_string.sub(
|
57
|
+
number_string.sub('#') { rand(1..9).to_s }.gsub('#') { rand(10).to_s }
|
54
58
|
end
|
55
59
|
|
56
60
|
def letterify(letter_string)
|
57
|
-
letter_string.gsub(
|
61
|
+
letter_string.gsub('?') { sample(ULetters) }
|
58
62
|
end
|
59
63
|
|
60
64
|
def bothify(string)
|
61
65
|
letterify(numerify(string))
|
62
66
|
end
|
63
67
|
|
68
|
+
def generate(as_type, &block)
|
69
|
+
PositionalGenerator.new(as_type, &block).generate
|
70
|
+
end
|
71
|
+
|
64
72
|
# Given a regular expression, attempt to generate a string
|
65
73
|
# that would match it. This is a rather simple implementation,
|
66
74
|
# so don't be shocked if it blows up on you in a spectacular fashion.
|
@@ -84,7 +92,7 @@ module Faker
|
|
84
92
|
reg = reg.source if reg.respond_to?(:source) # Handle either a Regexp or a String that looks like a Regexp
|
85
93
|
reg
|
86
94
|
.gsub(%r{^/?\^?}, '').gsub(%r{\$?/?$}, '') # Ditch the anchors
|
87
|
-
.gsub(/\{(\d+)\}/, '{\1,\1}').gsub(
|
95
|
+
.gsub(/\{(\d+)\}/, '{\1,\1}').gsub('?', '{0,1}') # All {2} become {2,2} and ? become {0,1}
|
88
96
|
.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]
|
89
97
|
.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)
|
90
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))) } # A{1,2} becomes A or AA or \d{3} becomes \d\d\d
|
@@ -99,7 +107,7 @@ module Faker
|
|
99
107
|
# with an array of values and selecting one of them.
|
100
108
|
def fetch(key)
|
101
109
|
fetched = sample(translate("faker.#{key}"))
|
102
|
-
if fetched&.match(%r{^/}) && fetched
|
110
|
+
if fetched&.match(%r{^/}) && fetched.match(%r{/$}) # A regex
|
103
111
|
regexify(fetched)
|
104
112
|
else
|
105
113
|
fetched
|
@@ -241,6 +249,10 @@ module Faker
|
|
241
249
|
list.shuffle(random: Faker::Config.random)
|
242
250
|
end
|
243
251
|
|
252
|
+
def shuffle!(list)
|
253
|
+
list.shuffle!(random: Faker::Config.random)
|
254
|
+
end
|
255
|
+
|
244
256
|
def rand(max = nil)
|
245
257
|
if max.nil?
|
246
258
|
Faker::Config.random.rand
|
@@ -263,4 +275,4 @@ module Faker
|
|
263
275
|
end
|
264
276
|
|
265
277
|
# require faker objects
|
266
|
-
Dir.glob(File.join(mydir, 'faker', '/**/*.rb')).
|
278
|
+
Dir.glob(File.join(mydir, 'faker', '/**/*.rb')).each { |file| require file }
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Based on Rails ActiveSupport Deprecator
|
4
|
+
# https://github.com/rails/rails/blob/main/activesupport/lib/active_support/deprecation/constant_accessor.rb
|
5
|
+
|
6
|
+
# rubocop:disable Style/ClassVars
|
7
|
+
module Faker
|
8
|
+
# Provides a way to rename generators, including their namespaces, with a deprecation cycle in which
|
9
|
+
# both the old and new names work, but using the old one prints a deprecation message.
|
10
|
+
#
|
11
|
+
# Deprecator provides a deprecate_generator method to be used when
|
12
|
+
# renaming a generator. For example, let's say we want to change the following Generator's
|
13
|
+
# name to <tt>Faker::NewGenerator</tt>:
|
14
|
+
#
|
15
|
+
# module Faker
|
16
|
+
# class Generator
|
17
|
+
# def self.generate
|
18
|
+
# "be kind"
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# To rename it, you need to do the update the name and declare the deprecation by
|
24
|
+
# including the <tt>Deprecator</tt> module and using the deprecate_generator method:
|
25
|
+
#
|
26
|
+
# module Faker
|
27
|
+
# class NewGenerator
|
28
|
+
# def self.generate
|
29
|
+
# "be kind"
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# include Deprecator
|
34
|
+
# deprecate_generator('DeprecatedGenerator', NewGenerator)
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# The first argument is a constant name (no colons) as a string. It is the name of
|
38
|
+
# the constant you want to deprecate.
|
39
|
+
#
|
40
|
+
# The second argument is the constant path of the replacement (no colons) as a constant.
|
41
|
+
#
|
42
|
+
# For this to work, a +const_missing+ hook is installed. When users
|
43
|
+
# reference the deprecated constant, the callback prints the
|
44
|
+
# message and constantizes the replacement.
|
45
|
+
#
|
46
|
+
# With that in place, references to <tt>Faker::Deprecator</tt> still work, they
|
47
|
+
# evaluate to <tt>Faker::NewGenerator</tt> now, and trigger a deprecation warning:
|
48
|
+
#
|
49
|
+
# Faker::Generator.generate
|
50
|
+
# # DEPRECATION WARNING: Faker::Generator is deprecated. Use Faker::NewGenerator instead
|
51
|
+
# # "be kind"
|
52
|
+
#
|
53
|
+
# For testing the deprecations, we provide <tt>assert_deprecated</tt>
|
54
|
+
# and <tt>assert_not_deprecated</tt> matchers.
|
55
|
+
#
|
56
|
+
# There's also a <tt>Faker::Deprecator.skip_warning</tt> helper to silence
|
57
|
+
# the deprecation messages in the *test* output. Use it for generators that have lots of tests
|
58
|
+
# to avoid too many noise when running the tests.
|
59
|
+
module Deprecator
|
60
|
+
def self.included(base)
|
61
|
+
extension = Module.new do
|
62
|
+
def const_missing(missing_const_name)
|
63
|
+
if class_variable_defined?(:@@_deprecated_constants) && (replacement = class_variable_get(:@@_deprecated_constants)[missing_const_name.to_s])
|
64
|
+
unless Faker::Deprecator.skip_warning?
|
65
|
+
deprecated_message = "#{name}::#{replacement[:old_generator]} is deprecated."
|
66
|
+
replacement_message = "Use #{replacement[:new_constant]} instead."
|
67
|
+
$stdout.puts("DEPRECATION WARNING: #{deprecated_message} #{replacement_message}")
|
68
|
+
end
|
69
|
+
|
70
|
+
return replacement[:new_constant]
|
71
|
+
end
|
72
|
+
|
73
|
+
super
|
74
|
+
end
|
75
|
+
|
76
|
+
def deprecate_generator(old_generator_name, new_generator_constant)
|
77
|
+
class_variable_set(:@@_deprecated_constants, {}) unless class_variable_defined?(:@@_deprecated_constants)
|
78
|
+
class_variable_get(:@@_deprecated_constants)[old_generator_name] = {
|
79
|
+
new_constant: new_generator_constant,
|
80
|
+
old_generator: old_generator_name
|
81
|
+
}
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
base.singleton_class.prepend extension
|
86
|
+
end
|
87
|
+
|
88
|
+
# Silence deprecation warnings within the block.
|
89
|
+
#
|
90
|
+
# Faker::Generator.generate
|
91
|
+
# # => DEPRECATION WARNING: Faker::Generator is deprecated. Use Faker::NewGenerator instead.
|
92
|
+
#
|
93
|
+
# Faker::Deprecator.skip_warning do
|
94
|
+
# Faker::Generator.generate
|
95
|
+
# end
|
96
|
+
# # => nil
|
97
|
+
def self.skip_warning
|
98
|
+
original = Faker::Deprecator.skip
|
99
|
+
Faker::Deprecator.skip = true
|
100
|
+
yield
|
101
|
+
ensure
|
102
|
+
Faker::Deprecator.skip = original
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.skip_warning?
|
106
|
+
@skip == true
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.skip
|
110
|
+
@skip ||= false
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.skip=(value)
|
114
|
+
@skip = value
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
# rubocop:enable Style/ClassVars
|