faker 3.4.1 → 3.5.1

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: 8af27d99c348c9ae7dc6d06e29566ba78ca5b7f38639697d17dcb4a8403e0497
4
- data.tar.gz: bd07375b615d5440b35e6c903a2ca68afcaecb8d0caed7eddac5e2a7d0c34946
3
+ metadata.gz: ad65b0b170d18a8541ff81c4db2ccce41263844bd877e4ecb0b78261a04f916a
4
+ data.tar.gz: 2c84244f6994575b1d94fb1a7e60a3d16122e17aeed81bcb6945360aeb5b7eda
5
5
  SHA512:
6
- metadata.gz: 6b54896707a3b7cd26bed81a5ee99af3e0d7cba59814f977c27d308ade1d56ba7670b83e4404982f1e51d1e42b9e8c229619e0737cd27c44a6922c6798084e04
7
- data.tar.gz: 13c40edb228c8bdbbc5ac704775762dc19794c006a6ccd8d75dc7c3528ae19245a7163be4ffe213d11ae99529ad297a1b2ba356dd5ade3c500fa72312db04308
6
+ metadata.gz: a436fa77b8d61b96a5f52748061e823528c234b5e8ce5e6e3876254eaddb3f72b6fca43e52c0aeed3d6e00701c2ab81b77a192846929d46920f088182e20e5d9
7
+ data.tar.gz: 0d2eb003ccd5492d09a2e5565994380bbb61fb1cfa0ca94efcae3f556e27bce231dfc13e643be150893040137e6c856011c7891fcde0b19c4aea99bf3d2853a4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,111 @@
1
1
  # Changelog
2
2
 
3
+ ## [v3.5.1](https://github.com/faker-ruby/faker/tree/v3.5.1) (2024-10-18)
4
+
5
+ Happy October! 🎃
6
+
7
+ This version **drops support for Ruby < 3.0**. We only support one EOL Ruby version at a time. Please upgrade to Ruby 3.0 to update to this and future versions of faker-ruby.
8
+
9
+ Besides that, this version removes deprecated generators, fixes some bugs, and adds a Security Policy.
10
+
11
+ Thanks to all contributors!
12
+
13
+ ## Breaking Changes
14
+ * Drop support for Ruby 2.7 by @tatheerf02 in https://github.com/faker-ruby/faker/pull/3006
15
+ * Removes deprecated generators by @stefannibrasil in https://github.com/faker-ruby/faker/pull/3014
16
+
17
+ The following deprecated generators are being removed. Please use the new generators:
18
+
19
+
20
+ | Deprecated | New |
21
+ | -------- | ------- |
22
+ | Faker::TvShows::TheFreshPrinceOfBelAir.celebrity | Faker::TvShows::TheFreshPrinceOfBelAir.actor |
23
+ | Faker::TvShows::Buffy.celebrity | Faker::TvShows::Buffy.actor |
24
+ | Faker::TvShows::DrWho.villian | Faker::TvShows::DrWho.villain |
25
+ | Faker::Games::HeroesOfTheStorm.class | Faker::Games::HeroesOfTheStorm.class_name |
26
+ | Faker::JapaneseMedia::FmaBrotherhood | Faker::JapaneseMedia::FullmetalAlchemistBrotherhood |
27
+ | Faker::Show | Faker::Theater |
28
+ | Faker::Australia | Faker::Locations::Australia |
29
+ | Faker::IDNumber | Faker::IdNumber |
30
+
31
+ ### Improvements & Bug fixes
32
+ * Fix typos by @tagliala in https://github.com/faker-ruby/faker/pull/2982
33
+ * Fix benchmark:all_methods task by excluding Faker::Deprecator module from benchmark target by @amatsuda in https://github.com/faker-ruby/faker/pull/2988
34
+ * Add Brazilian Portuguese translations for `Faker::Subscription` by @murichristopher in https://github.com/faker-ruby/faker/pull/2960
35
+ * Deprecator improvements by @stefannibrasil in https://github.com/faker-ruby/faker/pull/2997
36
+ * Faker::Alphanumeric.alphanumeric determinism fix by @admtnnr in https://github.com/faker-ruby/faker/pull/2996
37
+ * Remove CodeClimate badges by @tagliala in https://github.com/faker-ruby/faker/pull/3003
38
+ * Update Company.logo example url by @dirschn in https://github.com/faker-ruby/faker/pull/3007
39
+ * fix(music.band): removes leading whitespace by @JeremasPosta in https://github.com/faker-ruby/faker/pull/3015
40
+ * Create SECURITY.md by @stefannibrasil in https://github.com/faker-ruby/faker/pull/3016
41
+
42
+ ### Update local dependencies
43
+ * Bump i18n from 1.14.5 to 1.14.6 by @dependabot in https://github.com/faker-ruby/faker/pull/3005
44
+ * Bump minitest from 5.24.1 to 5.25.0 by @dependabot in https://github.com/faker-ruby/faker/pull/2991
45
+ * Bump rubocop-minitest from 0.35.1 to 0.36.0 by @dependabot in https://github.com/faker-ruby/faker/pull/2999
46
+ * Bump yard from 0.9.36 to 0.9.37 by @dependabot in https://github.com/faker-ruby/faker/pull/3000
47
+ * Bump rubocop from 1.65.1 to 1.66.1 by @dependabot in https://github.com/faker-ruby/faker/pull/3001
48
+
49
+ ## New Contributors
50
+ * @murichristopher made their first contribution in https://github.com/faker-ruby/faker/pull/2960
51
+ * @admtnnr made their first contribution in https://github.com/faker-ruby/faker/pull/2996
52
+ * @dirschn made their first contribution in https://github.com/faker-ruby/faker/pull/3007
53
+ * @tatheerf02 made their first contribution in https://github.com/faker-ruby/faker/pull/3006
54
+ * @JeremasPosta made their first contribution in https://github.com/faker-ruby/faker/pull/3015
55
+
56
+ **Full Changelog**: https://github.com/faker-ruby/faker/compare/v3.4.2...v3.5.1
57
+
58
+ --------------------------------------
59
+
60
+ ## [v3.4.2](https://github.com/faker-ruby/faker/tree/v3.4.2) (2024-07-16)
61
+
62
+ Happy July with a new faker-ruby release.
63
+
64
+ This version:
65
+
66
+ - introduces a breaking change for `Faker::NationalHealthService.british_number` (more details below)
67
+ - adds translation for some generators
68
+ - fixes bugs
69
+
70
+ ### Breaking changes
71
+
72
+ The NHS sets aside a range of numbers from 999 000 0000 to 999 999 9999 for test purposes. The old range could
73
+ produce NHS numbers that were in use by real patients in the UK/England and Wales. In this version, `Faker::NationalHealthService.british_number` uses the test range for creating NHS numbers rather than the previous 400 000 0010 to 499 999 9999 range.
74
+
75
+ Breaking change was introduced in "Add test range param to NHS numbers" by @neanias in https://github.com/faker-ruby/faker/pull/2947
76
+
77
+ ### Improvements & Bug fixes
78
+
79
+ * Add Bank and Sport to Swedish locale by @twk-mn in https://github.com/faker-ruby/faker/pull/2961
80
+ * docs: update with notes about validity for zips by @garrettgregor in https://github.com/faker-ruby/faker/pull/2963
81
+ * `Faker::Games::Dota` missing quotes and new heroes by @arthurka-o in https://github.com/faker-ruby/faker/pull/2907
82
+ * Add phone_number.country_code and address.full_address in locale sv by @larkro in https://github.com/faker-ruby/faker/pull/2965
83
+ * Fix typo by @fynsta in https://github.com/faker-ruby/faker/pull/2968
84
+ * fix: `Faker::Internet.username` should not generate duplicated punctuation by @thdaraujo in https://github.com/faker-ruby/faker/pull/2970
85
+ * Update dog breed names for `en-US` locale by @mononoken in https://github.com/faker-ruby/faker/pull/2972
86
+ * Add `Deprecator.skip_warning?` ability to silence deprecators on tests by @keshavbiswa in https://github.com/faker-ruby/faker/pull/2956
87
+
88
+ ### Update local dependencies
89
+
90
+ * Bump timecop from 0.9.9 to 0.9.10 by @dependabot in https://github.com/faker-ruby/faker/pull/2969
91
+ * Bump minitest from 5.23.1 to 5.24.1 by @dependabot in https://github.com/faker-ruby/faker/pull/2975
92
+ * Bump bundler version to `2.4.22` by @thdaraujo in https://github.com/faker-ruby/faker/pull/2978
93
+ * Bump rubocop from 1.64.1 to 1.65.0 by @dependabot in https://github.com/faker-ruby/faker/pull/2979
94
+ * Bump rubocop-minitest from 0.35.0 to 0.35.1 by @dependabot in https://github.com/faker-ruby/faker/pull/2980
95
+
96
+ ## New Contributors
97
+ * @twk-mn made their first contribution in https://github.com/faker-ruby/faker/pull/2961
98
+ * @neanias made their first contribution in https://github.com/faker-ruby/faker/pull/2947
99
+ * @garrettgregor made their first contribution in https://github.com/faker-ruby/faker/pull/2963
100
+ * @arthurka-o made their first contribution in https://github.com/faker-ruby/faker/pull/2907
101
+ * @larkro made their first contribution in https://github.com/faker-ruby/faker/pull/2965
102
+ * @fynsta made their first contribution in https://github.com/faker-ruby/faker/pull/2968
103
+ * @mononoken made their first contribution in https://github.com/faker-ruby/faker/pull/2972
104
+
105
+ **Full Changelog**: https://github.com/faker-ruby/faker/compare/v.3.4.1...v3.4.2
106
+
107
+ ---------------------------------
108
+
3
109
  ## [v3.4.1](https://github.com/faker-ruby/faker/tree/v3.4.1) (2024-05-28)
4
110
 
5
111
  ### What's changed
@@ -2500,7 +2606,7 @@ Fix lib/faker/version.rb
2500
2606
  - Fixed typo in dutch translation [\#679](https://github.com/stympy/faker/pull/679) ([nschmoller](https://github.com/nschmoller))
2501
2607
  - Add pokemon [\#677](https://github.com/stympy/faker/pull/677) ([bakunyo](https://github.com/bakunyo))
2502
2608
  - Food [\#672](https://github.com/stympy/faker/pull/672) ([martymclaugh](https://github.com/martymclaugh))
2503
- - Added charcaters and houses data for game of thrones in en.yml [\#670](https://github.com/stympy/faker/pull/670) ([vamsipavanmahesh](https://github.com/vamsipavanmahesh))
2609
+ - Added characters and houses data for game of thrones in en.yml [\#670](https://github.com/stympy/faker/pull/670) ([vamsipavanmahesh](https://github.com/vamsipavanmahesh))
2504
2610
  - add Faker::Commerce.promotion\_code [\#669](https://github.com/stympy/faker/pull/669) ([jGRUBBS](https://github.com/jGRUBBS))
2505
2611
  - Eliminate and prevent leading and trailing white space [\#665](https://github.com/stympy/faker/pull/665) ([retroGiant89](https://github.com/retroGiant89))
2506
2612
  - Fix for memory overflow error Issue: \#478 [\#664](https://github.com/stympy/faker/pull/664) ([anuj-verma](https://github.com/anuj-verma))
data/README.md CHANGED
@@ -4,8 +4,6 @@
4
4
  [![Tests](https://github.com/faker-ruby/faker/workflows/Tests/badge.svg)](https://github.com/faker-ruby/faker/actions?query=workflow%3ATests)
5
5
  [![Gem Version](https://badge.fury.io/rb/faker.svg)](https://badge.fury.io/rb/faker)
6
6
  [![Inline docs](https://inch-ci.org/github/faker-ruby/faker.svg?branch=main)](https://inch-ci.org/github/faker-ruby/faker)
7
- [![Test Coverage](https://api.codeclimate.com/v1/badges/ef54c7f9df86e965d64b/test_coverage)](https://codeclimate.com/github/stympy/faker/test_coverage)
8
- [![Maintainability](https://api.codeclimate.com/v1/badges/ef54c7f9df86e965d64b/maintainability)](https://codeclimate.com/github/stympy/faker/maintainability)
9
7
 
10
8
  Faker is a port of [Perl's Data::Faker library](https://metacpan.org/pod/Data::Faker).
11
9
  It's a library for generating fake data such as names, addresses, and phone numbers.
@@ -119,8 +119,8 @@ module Faker
119
119
  return numerify(letterified_string, leading_zero: true)
120
120
  end
121
121
 
122
- # provide a zip code that is valid for the state provided
123
- # see http://www.fincen.gov/forms/files/us_state_territory_zip_codes.pdf
122
+ # provide a zip code that may be valid for the state provided
123
+ # note: zip code may appear in the correct format for the state provided but may not be an actual state zip.
124
124
  bothify(fetch("address.postcode_by_state.#{state_abbreviation}"))
125
125
  end
126
126
 
@@ -60,7 +60,7 @@ module Faker
60
60
  randoms = Array.new(random_count) { sample(ALPHANUMS) }
61
61
 
62
62
  combined = alphas + numbers + randoms
63
- combined.shuffle.join
63
+ shuffle!(combined).join
64
64
  end
65
65
  end
66
66
  end
@@ -12,7 +12,7 @@ module Faker
12
12
  ].freeze
13
13
  ZA_RACE_DIGIT = '8'
14
14
  ZA_CITIZENSHIP_DIGITS = %w[0 1].freeze
15
- BRAZILIAN_ID_FORMAT = /(\d{1,2})(\d{3})(\d{3})([\dX])/.freeze
15
+ BRAZILIAN_ID_FORMAT = /(\d{1,2})(\d{3})(\d{3})([\dX])/
16
16
  BRAZILIAN_ID_FROM = 10_000_000
17
17
  BRAZILIAN_ID_TO = 99_999_999
18
18
 
@@ -421,7 +421,4 @@ module Faker
421
421
  end
422
422
  end
423
423
  end
424
-
425
- include Faker::Deprecator
426
- deprecate_generator('IDNumber', IdNumber)
427
424
  end
@@ -65,7 +65,7 @@ module Faker
65
65
  with_locale(:en) do
66
66
  case specifier
67
67
  when ::String
68
- names = specifier&.gsub("'", '')&.split
68
+ names = specifier.gsub("'", '').scan(/[[:word:]]+/)
69
69
  shuffled_names = shuffle(names)
70
70
 
71
71
  return shuffled_names.join(sample(separators)).downcase
@@ -22,7 +22,7 @@ module Faker
22
22
  end
23
23
 
24
24
  ##
25
- # Produces a random valid reference accoring to the International bank slip reference https://en.wikipedia.org/wiki/Creditor_Reference
25
+ # Produces a random valid reference according to the International bank slip reference https://en.wikipedia.org/wiki/Creditor_Reference
26
26
  #
27
27
  # @param ref [String] Specifies reference base.
28
28
  # @return [String]
@@ -6,14 +6,17 @@ module Faker
6
6
  ##
7
7
  # Produces a random British NHS number.
8
8
  #
9
+ # The NHS sets aside a range of numbers from 999 000 0000 to 999 999 9999
10
+ # for test purposes.
11
+ #
9
12
  # @return [String]
10
13
  #
11
14
  # @example
12
- # Faker::NationalHealthService.british_number #=> "403 958 5577"
15
+ # Faker::NationalHealthService.british_number #=> "999 464 0232"
13
16
  #
14
17
  # @faker.version 1.9.2
15
18
  def british_number
16
- base_number = rand(400_000_001...499_999_999)
19
+ base_number = rand(999_000_001...999_999_999)
17
20
  # If the check digit is equivalent to 10, the number is invalid.
18
21
  # See https://en.wikipedia.org/wiki/NHS_number
19
22
  base_number -= 1 if check_digit(number: base_number) == 10
@@ -24,6 +27,8 @@ module Faker
24
27
  .join
25
28
  end
26
29
 
30
+ private
31
+
27
32
  ##
28
33
  # Produces a random British NHS number's check digit.
29
34
  #
@@ -46,7 +46,4 @@ module Faker
46
46
  end
47
47
  end
48
48
  end
49
-
50
- include Faker::Deprecator
51
- deprecate_generator('Show', Theater)
52
49
  end
@@ -48,12 +48,13 @@ module Faker
48
48
  # @return [String]
49
49
  #
50
50
  # @example
51
- # Faker::Vehicle.manufacture #=> "Lamborghini"
51
+ # Faker::Vehicle.manufacturer #=> "Lamborghini"
52
52
  #
53
53
  # @faker.version 1.6.4
54
- def manufacture
55
- fetch('vehicle.manufacture')
54
+ def manufacturer
55
+ fetch('vehicle.manufacturer')
56
56
  end
57
+ alias manufacture manufacturer
57
58
 
58
59
  ##
59
60
  # Produces a random vehicle make.
@@ -17,17 +17,6 @@ module Faker
17
17
  fetch('heroes_of_the_storm.battlegrounds')
18
18
  end
19
19
 
20
- ##
21
- # This method is deprecated. The implementation will be removed in a near future release.
22
- # Use `HeroesOfTheStorm.class_name` instead.
23
- #
24
- # @deprecated Use {#class_name} instead.
25
- def class
26
- warn '`HeroesOfTheStorm.class` is deprecated. Use `HeroesOfTheStorm.class_name` instead.'
27
-
28
- super
29
- end
30
-
31
20
  ##
32
21
  # Produces a class name from Heroes of the Storm.
33
22
  #
@@ -44,8 +44,5 @@ module Faker
44
44
  end
45
45
  end
46
46
  end
47
-
48
- include Faker::Deprecator
49
- deprecate_generator('FmaBrotherhood', FullmetalAlchemistBrotherhood)
50
47
  end
51
48
  end
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Faker
4
- extend Deprecator
5
-
6
4
  class Locations
7
5
  class Australia < Base
8
6
  class << self
@@ -48,5 +46,4 @@ module Faker
48
46
  end
49
47
  end
50
48
  end
51
- deprecate_generator('Australia', Locations::Australia)
52
49
  end
@@ -204,7 +204,7 @@ module Faker
204
204
  # @example
205
205
  # Faker::Movies::StarWars.droids
206
206
  #
207
- # @faker.versionn 1.6.2
207
+ # @faker.version 1.6.2
208
208
  def droids
209
209
  fetch_all('star_wars.droids')
210
210
  end
@@ -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,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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Faker # :nodoc:
4
- VERSION = '3.4.1'
4
+ VERSION = '3.5.1'
5
5
  end
data/lib/faker.rb CHANGED
@@ -5,7 +5,7 @@ mydir = __dir__
5
5
  require 'psych'
6
6
  require 'i18n'
7
7
 
8
- Dir.glob(File.join(mydir, 'helpers', '*.rb')).sort.each { |file| require file }
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
 
@@ -107,7 +107,7 @@ module Faker
107
107
  # with an array of values and selecting one of them.
108
108
  def fetch(key)
109
109
  fetched = sample(translate("faker.#{key}"))
110
- if fetched&.match(%r{^/}) && fetched&.match(%r{/$}) # A regex
110
+ if fetched&.match(%r{^/}) && fetched.match(%r{/$}) # A regex
111
111
  regexify(fetched)
112
112
  else
113
113
  fetched
@@ -249,6 +249,10 @@ module Faker
249
249
  list.shuffle(random: Faker::Config.random)
250
250
  end
251
251
 
252
+ def shuffle!(list)
253
+ list.shuffle!(random: Faker::Config.random)
254
+ end
255
+
252
256
  def rand(max = nil)
253
257
  if max.nil?
254
258
  Faker::Config.random.rand
@@ -271,4 +275,4 @@ module Faker
271
275
  end
272
276
 
273
277
  # require faker objects
274
- Dir.glob(File.join(mydir, 'faker', '/**/*.rb')).sort.each { |file| require file }
278
+ Dir.glob(File.join(mydir, 'faker', '/**/*.rb')).each { |file| require file }
@@ -1,16 +1,72 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Based on Rails ActiveSupport Deprecator
4
- # https://github.com/rails/rails/blob/6f0d1ad14b92b9f5906e44740fce8b4f1c7075dc/activesupport/lib/active_support/deprecation/constant_accessor.rb
4
+ # https://github.com/rails/rails/blob/main/activesupport/lib/active_support/deprecation/constant_accessor.rb
5
5
 
6
6
  # rubocop:disable Style/ClassVars
7
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.
8
59
  module Deprecator
9
60
  def self.included(base)
10
61
  extension = Module.new do
11
62
  def const_missing(missing_const_name)
12
63
  if class_variable_defined?(:@@_deprecated_constants) && (replacement = class_variable_get(:@@_deprecated_constants)[missing_const_name.to_s])
13
- $stdout.puts("DEPRECATION WARNING: #{name}::#{replacement[:old_generator]} is deprecated. Use #{replacement[:new_constant]} instead.")
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
+
14
70
  return replacement[:new_constant]
15
71
  end
16
72
 
@@ -19,12 +75,44 @@ module Faker
19
75
 
20
76
  def deprecate_generator(old_generator_name, new_generator_constant)
21
77
  class_variable_set(:@@_deprecated_constants, {}) unless class_variable_defined?(:@@_deprecated_constants)
22
- class_variable_get(:@@_deprecated_constants)[old_generator_name] = { new_constant: new_generator_constant, old_generator: old_generator_name }
78
+ class_variable_get(:@@_deprecated_constants)[old_generator_name] = {
79
+ new_constant: new_generator_constant,
80
+ old_generator: old_generator_name
81
+ }
23
82
  end
24
83
  end
25
84
 
26
85
  base.singleton_class.prepend extension
27
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
28
116
  end
29
117
  end
30
118
  # rubocop:enable Style/ClassVars