faker 2.1.2 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +41 -7
  3. data/README.md +2 -2
  4. data/lib/faker.rb +22 -1
  5. data/lib/faker/books/dune.rb +12 -2
  6. data/lib/faker/books/lovecraft.rb +54 -7
  7. data/lib/faker/default/address.rb +30 -5
  8. data/lib/faker/default/alphanumeric.rb +45 -7
  9. data/lib/faker/default/app.rb +16 -1
  10. data/lib/faker/default/avatar.rb +24 -1
  11. data/lib/faker/default/bank.rb +12 -2
  12. data/lib/faker/default/boolean.rb +6 -1
  13. data/lib/faker/default/chile_rut.rb +20 -2
  14. data/lib/faker/default/code.rb +22 -3
  15. data/lib/faker/default/commerce.rb +26 -3
  16. data/lib/faker/default/company.rb +12 -2
  17. data/lib/faker/default/crypto_coin.rb +18 -3
  18. data/lib/faker/default/date.rb +48 -5
  19. data/lib/faker/default/demographic.rb +6 -1
  20. data/lib/faker/default/driving_licence.rb +20 -4
  21. data/lib/faker/default/file.rb +36 -2
  22. data/lib/faker/default/fillmurray.rb +16 -1
  23. data/lib/faker/default/finance.rb +6 -1
  24. data/lib/faker/default/hipster.rb +78 -6
  25. data/lib/faker/default/id_number.rb +12 -2
  26. data/lib/faker/default/internet.rb +124 -13
  27. data/lib/faker/default/invoice.rb +22 -3
  28. data/lib/faker/default/json.rb +26 -2
  29. data/lib/faker/default/lorem.rb +120 -10
  30. data/lib/faker/default/lorem_flickr.rb +69 -5
  31. data/lib/faker/default/lorem_pixel.rb +26 -1
  32. data/lib/faker/default/markdown.rb +10 -1
  33. data/lib/faker/default/measurement.rb +48 -8
  34. data/lib/faker/default/name.rb +6 -1
  35. data/lib/faker/default/nhs.rb +6 -1
  36. data/lib/faker/default/number.rb +81 -11
  37. data/lib/faker/default/omniauth.rb +84 -5
  38. data/lib/faker/default/phone_number.rb +6 -1
  39. data/lib/faker/default/placeholdit.rb +24 -1
  40. data/lib/faker/default/relationship.rb +6 -1
  41. data/lib/faker/default/source.rb +22 -3
  42. data/lib/faker/default/string.rb +6 -1
  43. data/lib/faker/default/stripe.rb +24 -4
  44. data/lib/faker/default/time.rb +68 -4
  45. data/lib/faker/default/twitter.rb +26 -3
  46. data/lib/faker/default/types.rb +38 -5
  47. data/lib/faker/default/vehicle.rb +22 -3
  48. data/lib/faker/default/world_cup.rb +16 -2
  49. data/lib/faker/games/dota.rb +6 -1
  50. data/lib/faker/movies/star_wars.rb +6 -1
  51. data/lib/faker/version.rb +1 -1
  52. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7462443ac85163e4a2bfaaa60b52b0153d209004c68f498be7796bafdca56bb8
4
- data.tar.gz: 83792726058a2a4bcae5a9e65faebd7b89271323b04c509c5e85a3ed3dcf87d7
3
+ metadata.gz: b5587b3da998c6565466a5886c285dc46218d0c6be32bbc9d1578b2493ccca0a
4
+ data.tar.gz: da07c93a781ccaf2f57b79a220f05905913b11261d6c324ab54e63f7c4f757d3
5
5
  SHA512:
6
- metadata.gz: 13e01c3cf5c0f2f4813b4ebd5f47da32f5445234cb0bbc217e7b1b4836c8578b9e32bdafbafe68c9d9c8f85e2a14ec84a9fa13c3b611c3fa7f566b6bdf1176eb
7
- data.tar.gz: d4ff9c657474b461ed8b4f54ec16e982ba805d3bc5fd815757bcfbb67b3823fba776ba004af140a1afb6d5424990f6819eda943a7b4bdfe24841713b9eb29f4c
6
+ metadata.gz: e5e2770457c5eabde0476cbb1a6cd320c633ceb0dbb734636569dbd84471df2d85f47f1664f597a65ccfedda1af67340904b2cf64e3798edfa83481d11015a39
7
+ data.tar.gz: 16721c3cd11278e59c6df91b5a99f507c938e705d1eb9e20bd2fb26811819b5c781abf639d7ac8ab79b11ee3d7fea56c7d7ef876054c177e597116a967c41375
@@ -1,16 +1,50 @@
1
1
  # Change Log
2
2
 
3
- ## [v2.1.2](https://github.com/stympy/faker-ruby/faker/tree/2.1.2) (2019-10-08)
3
+ ## [v2.2.1](https://github.com/faker-ruby/faker/tree/v2.2.1) (2019-30-08)
4
+
5
+ ## Bug/Fixes
6
+
7
+ - [PR #1712](https://github.com/faker-ruby/faker/pull/1712) Fix number(digits: 1) always returns 0 [@ianlet](https://github.com/ianlet)
8
+
9
+ `Faker::Number.number(digits: 1)` was always returning `0`.
10
+
11
+ Fixing number with one digit caused the test_insignificant_zero to fail. As it seemed that the behavior tested by test_insignificant_zero was already covered by test_number and test_decimal, we removed it to prevent duplication.
12
+
13
+ ## [v2.2.0](https://github.com/faker-ruby/faker/tree/v2.2.0) (2019-25-08)
14
+
15
+ ## Deprecate
16
+
17
+ - [PR #1698](https://github.com/faker-ruby/faker/pull/1698) Add warn for positional arguments when using Faker 2.0 [@koic](https://github.com/koic)
18
+
19
+ Add deprecation warning for positional arguments to notify users that are coming from Faker version < 2.0. Its main goal is to make upgrades easier.
20
+
21
+ ## Documentation
22
+
23
+ - [PR #1688](https://github.com/faker-ruby/faker/pull/1688) Update README install instructions [@EduardoGHdez](https://github.com/EduardoGHdez)
24
+ - [PR #1689](https://github.com/faker-ruby/faker/pull/1689) Update README.md [@Zeragamba](https://github.com/Zeragamba)
25
+ - [PR #1690](https://github.com/faker-ruby/faker/pull/1690) Update issue url in PULL_REQUEST_TEMPLATE [@bugtender](https://github.com/bugtender)
26
+ - [PR #1703](https://github.com/faker-ruby/faker/pull/1703) Return HTTPS URLs from Lorem Flickr [@connorshea](https://github.com/connorshea)
27
+
28
+ ## Feature Request
29
+ - [PR #1686](https://github.com/faker-ruby/faker/pull/1686) Update test-unit gem to 3.3.3 [@connorshea](https://github.com/connorshea)
30
+
31
+ ## Bug/Fixes
32
+ - [PR #1702](https://github.com/faker-ruby/faker/pull/1702) Fix an argument for test_faker_stripe.rb [@koic](https://github.com/koic)
33
+ - [PR #1694](https://github.com/faker-ruby/faker/pull/1694) Ensure mix_case returns at least one lower and one upper case letter [@bpleslie](https://github.com/bpleslie)
34
+
35
+ ------------------------------------------------------------------------------
36
+
37
+ ## [v2.1.2](https://github.com/faker-ruby/faker/tree/v2.1.2) (2019-10-08)
4
38
 
5
39
  ## Enhancements
6
40
 
7
- - [PR #1495](https://github.com/stympy/faker/pull/1495) Add Brazilian documents generation and documentation [@lucasqueiroz](https://github.com/lucasqueiroz)
41
+ - [PR #1495](https://github.com/faker-ruby/faker/pull/1495) Add Brazilian documents generation and documentation [@lucasqueiroz](https://github.com/lucasqueiroz)
8
42
 
9
43
  ## Issues
10
44
 
11
45
  We had to use `bundled with 1.7.3` to avoid some issues.
12
46
 
13
- ## [v2.1.1](https://github.com/stympy/faker/tree/2.1.1) (2019-10-08)
47
+ ## [v2.1.1](https://github.com/faker-ruby/faker/tree/2.1.1) (2019-10-08)
14
48
 
15
49
  ## Bug/Fixes
16
50
 
@@ -24,20 +58,20 @@ Rollback Faker::Time changes because we should expect the date format from activ
24
58
 
25
59
  ## Documentation
26
60
 
27
- - [PR #1677](https://github.com/stympy/faker/pull/1677) Fix docs for Internet#password generator [@ur5us](https://github.com/ur5us)
61
+ - [PR #1677](https://github.com/faker-ruby/faker/pull/1677) Fix docs for Internet#password generator [@ur5us](https://github.com/ur5us)
28
62
 
29
63
  ------------------------------------------------------------------------------
30
64
 
31
- ## [v2.1.0](https://github.com/stympy/faker/tree/2.1.0) (2019-31-07)
65
+ ## [v2.1.0](https://github.com/faker-ruby/faker/tree/v2.1.0) (2019-31-07)
32
66
 
33
67
  ## Bug/Fixes
34
- - [PR #1675](https://github.com/stympy/faker/pull/1675) Fix off-by-one error when formatting month names [@jutonz](https://github.com/jutonz)
68
+ - [PR #1675](https://github.com/faker-ruby/faker/pull/1675) Fix off-by-one error when formatting month names [@jutonz](https://github.com/jutonz)
35
69
 
36
70
  This change required a quick release because it's a breaking issue. Every place where I18n.l() was used began to display the wrong date, causing test suite to fail.
37
71
 
38
72
  ------------------------------------------------------------------------------
39
73
 
40
- ## [v2.0](https://github.com/stympy/faker/tree/2.0) (2019-31-07)
74
+ ## [v2.0](https://github.com/faker-ruby/faker/tree/v2.0) (2019-31-07)
41
75
 
42
76
  ## Important Note:
43
77
 
data/README.md CHANGED
@@ -55,7 +55,7 @@ gem install faker
55
55
  Note: if you are getting a `uninitialized constant Faker::[some_class]` error, your version of the gem is behind the one documented here. To make sure that your gem is the one documented here, change the line in your Gemfile to:
56
56
 
57
57
  ```ruby
58
- gem 'faker', :git => 'https://github.com/stympy/faker.git', :branch => 'master'
58
+ gem 'faker', :git => 'https://github.com/faker-ruby/faker.git', :branch => 'master'
59
59
  ```
60
60
 
61
61
  ## Usage
@@ -117,7 +117,7 @@ Faker::Company.bs #=> "cultivate viral synergies"
117
117
  **NOTE: Some of the generators below aren't released yet. If you want to use them, change the line in your gemfile to:**
118
118
 
119
119
  ```ruby
120
- gem 'faker', :git => 'https://github.com/stympy/faker.git', :branch => 'master'
120
+ gem 'faker', :git => 'https://github.com/faker-ruby/faker.git', :branch => 'master'
121
121
  ```
122
122
 
123
123
  ### Default
@@ -40,9 +40,12 @@ module Faker
40
40
  class Base
41
41
  Numbers = Array(0..9)
42
42
  ULetters = Array('A'..'Z')
43
- Letters = ULetters + Array('a'..'z')
43
+ LLetters = Array('a'..'z')
44
+ Letters = ULetters + LLetters
44
45
 
45
46
  class << self
47
+ NOT_GIVEN = Object.new
48
+
46
49
  ## by default numerify results do not start with a zero
47
50
  def numerify(number_string, leading_zero: false)
48
51
  return number_string.gsub(/#/) { rand(10).to_s } if leading_zero
@@ -245,6 +248,24 @@ module Faker
245
248
  ensure
246
249
  I18n.enforce_available_locales = old_enforce_available_locales
247
250
  end
251
+
252
+ private
253
+
254
+ # Workaround for emulating `warn '...', uplevel: 1` in Ruby 2.4 or lower.
255
+ def warn_with_uplevel(message, uplevel: 1)
256
+ at = parse_caller(caller[uplevel]).join(':')
257
+ warn "#{at}: #{message}"
258
+ end
259
+
260
+ def parse_caller(at)
261
+ # rubocop:disable Style/GuardClause
262
+ if /^(.+?):(\d+)(?::in `.*')?/ =~ at
263
+ file = Regexp.last_match(1)
264
+ line = Regexp.last_match(2).to_i
265
+ [file, line]
266
+ end
267
+ # rubocop:enable Style/GuardClause
268
+ end
248
269
  end
249
270
  end
250
271
  end
@@ -19,7 +19,12 @@ module Faker
19
19
  fetch('dune.planets')
20
20
  end
21
21
 
22
- def quote(character: nil)
22
+ def quote(legacy_character = NOT_GIVEN, character: nil)
23
+ if legacy_character != NOT_GIVEN
24
+ warn_with_uplevel 'Passing `character` with the 1st argument of `Dune.quote` is deprecated. Use keyword argument like `Dune.quote(character: ...)` instead.', uplevel: 1
25
+ character = legacy_character
26
+ end
27
+
23
28
  quoted_characters = translate('faker.dune.quotes').keys
24
29
 
25
30
  if character.nil?
@@ -36,7 +41,12 @@ module Faker
36
41
  fetch('dune.quotes.' + character)
37
42
  end
38
43
 
39
- def saying(source: nil)
44
+ def saying(legacy_source = NOT_GIVEN, source: nil)
45
+ if legacy_source != NOT_GIVEN
46
+ warn_with_uplevel 'Passing `source` with the 1st argument of `Dune.saying` is deprecated. Use keyword argument like `Dune.saying(source: ...)` instead.', uplevel: 1
47
+ source = legacy_source
48
+ end
49
+
40
50
  sourced_sayings = translate('faker.dune.sayings').keys
41
51
 
42
52
  if source.nil?
@@ -8,7 +8,12 @@ module Faker
8
8
  fetch('lovecraft.location')
9
9
  end
10
10
 
11
- def fhtagn(number: 1)
11
+ def fhtagn(legacy_number = NOT_GIVEN, number: 1)
12
+ if legacy_number != NOT_GIVEN
13
+ warn_with_uplevel 'Passing `number` with the 1st argument of `Lovecraft.fhtagn` is deprecated. Use keyword argument like `Lovecraft.fhtagn(number: ...)` instead.', uplevel: 1
14
+ number = legacy_number
15
+ end
16
+
12
17
  Array.new(number) { fetch('lovecraft.fhtagn') }.join('. ')
13
18
  end
14
19
 
@@ -20,7 +25,16 @@ module Faker
20
25
  fetch('lovecraft.tome')
21
26
  end
22
27
 
23
- def sentence(word_count: 4, random_words_to_add: 6)
28
+ def sentence(legacy_word_count = NOT_GIVEN, legacy_random_words_to_add = NOT_GIVEN, word_count: 4, random_words_to_add: 6)
29
+ if legacy_word_count != NOT_GIVEN
30
+ warn_with_uplevel 'Passing `word_count` with the 1st argument of `Lovecraft.sentence` is deprecated. Use keyword argument like `Lovecraft.sentence(word_count: ...)` instead.', uplevel: 1
31
+ word_count = legacy_word_count
32
+ end
33
+ if legacy_random_words_to_add != NOT_GIVEN
34
+ warn_with_uplevel 'Passing `random_words_to_add` with the 2nd argument of `Lovecraft.sentence` is deprecated. Use keyword argument like `Lovecraft.sentence(random_words_to_add: ...)` instead.', uplevel: 1
35
+ random_words_to_add = legacy_random_words_to_add
36
+ end
37
+
24
38
  words(number: word_count + rand(random_words_to_add.to_i).to_i, spaces_allowed: true).join(' ').capitalize + '.'
25
39
  end
26
40
 
@@ -29,7 +43,16 @@ module Faker
29
43
  random_word =~ /\s/ ? word : random_word
30
44
  end
31
45
 
32
- def words(number: 3, spaces_allowed: false)
46
+ def words(legacy_number = NOT_GIVEN, legacy_spaces_allowed = NOT_GIVEN, number: 3, spaces_allowed: false)
47
+ if legacy_number != NOT_GIVEN
48
+ warn_with_uplevel 'Passing `number` with the 1st argument of `Lovecraft.words` is deprecated. Use keyword argument like `Lovecraft.words(number: ...)` instead.', uplevel: 1
49
+ number = legacy_number
50
+ end
51
+ if legacy_spaces_allowed != NOT_GIVEN
52
+ warn_with_uplevel 'Passing `spaces_allowed` with the 2nd argument of `Lovecraft.words` is deprecated. Use keyword argument like `Lovecraft.words(spaces_allowed: ...)` instead.', uplevel: 1
53
+ spaces_allowed = legacy_spaces_allowed
54
+ end
55
+
33
56
  resolved_num = resolve(number)
34
57
  word_list = translate('faker.lovecraft.words')
35
58
  word_list *= ((resolved_num / word_list.length) + 1)
@@ -40,7 +63,12 @@ module Faker
40
63
  words.each_with_index { |w, i| words[i] = word if w =~ /\s/ }
41
64
  end
42
65
 
43
- def sentences(number: 3)
66
+ def sentences(legacy_number = NOT_GIVEN, number: 3)
67
+ if legacy_number != NOT_GIVEN
68
+ warn_with_uplevel 'Passing `number` with the 1st argument of `Lovecraft.sentences` is deprecated. Use keyword argument like `Lovecraft.sentences(number: ...)` instead.', uplevel: 1
69
+ number = legacy_number
70
+ end
71
+
44
72
  [].tap do |sentences|
45
73
  1.upto(resolve(number)) do
46
74
  sentences << sentence(word_count: 3)
@@ -48,11 +76,25 @@ module Faker
48
76
  end
49
77
  end
50
78
 
51
- def paragraph(sentence_count: 3, random_sentences_to_add: 3)
79
+ def paragraph(legacy_sentence_count = NOT_GIVEN, legacy_random_sentences_to_add = NOT_GIVEN, sentence_count: 3, random_sentences_to_add: 3)
80
+ if legacy_sentence_count != NOT_GIVEN
81
+ warn_with_uplevel 'Passing `sentence_count` with the 1st argument of `Lovecraft.paragraph` is deprecated. Use keyword argument like `Lovecraft.paragraph(sentence_count: ...)` instead.', uplevel: 1
82
+ sentence_count = legacy_sentence_count
83
+ end
84
+ if legacy_random_sentences_to_add != NOT_GIVEN
85
+ warn_with_uplevel 'Passing `random_sentences_to_add` with the 2nd argument of `Lovecraft.paragraph` is deprecated. Use keyword argument like `Lovecraft.paragraph(random_sentences_to_add: ...)` instead.', uplevel: 1
86
+ random_sentences_to_add = legacy_random_sentences_to_add
87
+ end
88
+
52
89
  sentences(number: resolve(sentence_count) + rand(random_sentences_to_add.to_i).to_i).join(' ')
53
90
  end
54
91
 
55
- def paragraphs(number: 3)
92
+ def paragraphs(legacy_number = NOT_GIVEN, number: 3)
93
+ if legacy_number != NOT_GIVEN
94
+ warn_with_uplevel 'Passing `number` with the 1st argument of `Lovecraft.paragraphs` is deprecated. Use keyword argument like `Lovecraft.paragraphs(number: ...)` instead.', uplevel: 1
95
+ number = legacy_number
96
+ end
97
+
56
98
  [].tap do |paragraphs|
57
99
  1.upto(resolve(number)) do
58
100
  paragraphs << paragraph(sentence_count: 3)
@@ -60,7 +102,12 @@ module Faker
60
102
  end
61
103
  end
62
104
 
63
- def paragraph_by_chars(characters: 256)
105
+ def paragraph_by_chars(legacy_characters = NOT_GIVEN, characters: 256)
106
+ if legacy_characters != NOT_GIVEN
107
+ warn_with_uplevel 'Passing `characters` with the 1st argument of `Lovecraft.paragraph_by_chars` is deprecated. Use keyword argument like `Lovecraft.paragraph_by_chars(characters: ...)` instead.', uplevel: 1
108
+ characters = legacy_characters
109
+ end
110
+
64
111
  paragraph = paragraph(sentence_count: 3)
65
112
 
66
113
  paragraph += ' ' + paragraph(sentence_count: 3) while paragraph.length < characters
@@ -5,7 +5,12 @@ module Faker
5
5
  flexible :address
6
6
 
7
7
  class << self
8
- def city(options: {})
8
+ def city(legacy_options = NOT_GIVEN, options: {})
9
+ if legacy_options != NOT_GIVEN
10
+ warn_with_uplevel 'Passing `options` with the 1st argument of `Address.city` is deprecated. Use keyword argument like `Address.city(options: ...)` instead.', uplevel: 1
11
+ options = legacy_options
12
+ end
13
+
9
14
  parse(options[:with_state] ? 'address.city_with_state' : 'address.city')
10
15
  end
11
16
 
@@ -13,7 +18,12 @@ module Faker
13
18
  parse('address.street_name')
14
19
  end
15
20
 
16
- def street_address(include_secondary: false)
21
+ def street_address(legacy_include_secondary = NOT_GIVEN, include_secondary: false)
22
+ if legacy_include_secondary != NOT_GIVEN
23
+ warn_with_uplevel 'Passing `include_secondary` with the 1st argument of `Address.street_address` is deprecated. Use keyword argument like `Address.street_address(include_secondary: ...)` instead.', uplevel: 1
24
+ include_secondary = legacy_include_secondary
25
+ end
26
+
17
27
  numerify(parse('address.street_address') + (include_secondary ? ' ' + secondary_address : ''))
18
28
  end
19
29
 
@@ -29,7 +39,12 @@ module Faker
29
39
  parse('address.community')
30
40
  end
31
41
 
32
- def zip_code(state_abbreviation: '')
42
+ def zip_code(legacy_state_abbreviation = NOT_GIVEN, state_abbreviation: '')
43
+ if legacy_state_abbreviation != NOT_GIVEN
44
+ warn_with_uplevel 'Passing `state_abbreviation` with the 1st argument of `Address.zip_code` is deprecated. Use keyword argument like `Address.zip_code(state_abbreviation: ...)` instead.', uplevel: 1
45
+ state_abbreviation = legacy_state_abbreviation
46
+ end
47
+
33
48
  if state_abbreviation.empty?
34
49
  letterified_string = letterify(fetch('address.postcode'))
35
50
  return numerify(letterified_string, leading_zero: true)
@@ -71,11 +86,21 @@ module Faker
71
86
  fetch('address.country')
72
87
  end
73
88
 
74
- def country_by_code(code: 'US')
89
+ def country_by_code(legacy_code = NOT_GIVEN, code: 'US')
90
+ if legacy_code != NOT_GIVEN
91
+ warn_with_uplevel 'Passing `code` with the 1st argument of `Address.country_by_code` is deprecated. Use keyword argument like `Address.country_by_code(code: ...)` instead.', uplevel: 1
92
+ code = legacy_code
93
+ end
94
+
75
95
  fetch('address.country_by_code.' + code)
76
96
  end
77
97
 
78
- def country_name_to_code(name: 'united_states')
98
+ def country_name_to_code(legacy_name = NOT_GIVEN, name: 'united_states')
99
+ if legacy_name != NOT_GIVEN
100
+ warn_with_uplevel 'Passing `name` with the 1st argument of `Address.country_name_to_code` is deprecated. Use keyword argument like `Address.country_name_to_code(name: ...)` instead.', uplevel: 1
101
+ name = legacy_name
102
+ end
103
+
79
104
  fetch('address.country_by_name.' + name)
80
105
  end
81
106
 
@@ -2,22 +2,60 @@
2
2
 
3
3
  module Faker
4
4
  class Alphanumeric < Base
5
- class << self
6
- ALPHABET = ('a'..'z').to_a
7
- ALPHANUMS = ALPHABET + (0..9).to_a
5
+ ALPHANUMS = LLetters + Numbers
8
6
 
9
- def alpha(number: 32)
7
+ class << self
8
+ def alpha(legacy_number = NOT_GIVEN, number: 32)
9
+ if legacy_number != NOT_GIVEN
10
+ warn_with_uplevel 'Passing `number` with the 1st argument of `Alphanumeric.alpha` is deprecated. Use keyword argument like `Alphanumeric.alpha(number: ...)` instead.', uplevel: 1
11
+ number = legacy_number
12
+ end
10
13
  char_count = resolve(number)
11
14
  return '' if char_count.to_i < 1
12
15
 
13
- Array.new(char_count) { sample(ALPHABET) }.join
16
+ Array.new(char_count) { sample(self::LLetters) }.join
14
17
  end
15
18
 
16
- def alphanumeric(number: 32)
19
+ ##
20
+ # Produces a random string of alphanumeric characters
21
+ #
22
+ # @param [Integer] number
23
+ # @param [Integer] min_alpha
24
+ # @param [Integer] min_numeric
25
+ #
26
+ # @return [String]
27
+ #
28
+ # @example Faker::Alphanumeric.alphanumeric(number: 10) #=> "3yfq2phxtb"
29
+ # @example Faker::Alphanumeric.alphanumeric(number: 10, min_alpha: 3) #=> "3yfq2phxtb"
30
+ # @example Faker::Alphanumeric.alphanumeric(number: 10, min_alpha: 3, min_numeric: 3) #=> "3yfq2phx8b"
31
+ #
32
+ # @faker.version 2.1.3
33
+ def alphanumeric(legacy_number = NOT_GIVEN, number: 32, min_alpha: 0, min_numeric: 0)
34
+ if legacy_number != NOT_GIVEN
35
+ warn_with_uplevel 'Passing `number` with the 1st argument of `Alphanumeric.alphanumeric` is deprecated. Use keyword argument like `Alphanumeric.alphanumeric(number: ...)` instead.', uplevel: 1
36
+ number = legacy_number
37
+ end
17
38
  char_count = resolve(number)
18
39
  return '' if char_count.to_i < 1
40
+ raise ArgumentError, 'min_alpha must be greater than or equal to 0' if min_alpha&.negative?
41
+ raise ArgumentError, 'min_numeric must be greater than or equal to 0' if min_numeric&.negative?
42
+
43
+ if min_alpha.zero? && min_numeric.zero?
44
+ return Array.new(char_count) { sample(ALPHANUMS) }.join
45
+ end
46
+
47
+ if min_alpha + min_numeric > char_count
48
+ raise ArgumentError, 'min_alpha + min_numeric must be <= number'
49
+ end
50
+
51
+ random_count = char_count - min_alpha - min_numeric
52
+
53
+ alphas = Array.new(min_alpha) { sample(self::LLetters) }
54
+ numbers = Array.new(min_numeric) { sample(self::Numbers) }
55
+ randoms = Array.new(random_count) { sample(ALPHANUMS) }
19
56
 
20
- Array.new(char_count) { sample(ALPHANUMS) }.join
57
+ combined = alphas + numbers + randoms
58
+ combined.shuffle.join
21
59
  end
22
60
  end
23
61
  end
@@ -15,7 +15,22 @@ module Faker
15
15
  parse('app.author')
16
16
  end
17
17
 
18
- def semantic_version(major: 0..9, minor: 0..9, patch: 1..9)
18
+ # rubocop:disable Metrics/ParameterLists
19
+ def semantic_version(legacy_major = NOT_GIVEN, legacy_minor = NOT_GIVEN, legacy_patch = NOT_GIVEN, major: 0..9, minor: 0..9, patch: 1..9)
20
+ # rubocop:enable Metrics/ParameterLists
21
+ if legacy_major != NOT_GIVEN
22
+ warn_with_uplevel 'Passing `major` with the 1st argument of `App.semantic_version` is deprecated. Use keyword argument like `App.semantic_version(major: ...)` instead.', uplevel: 1
23
+ major = legacy_major
24
+ end
25
+ if legacy_minor != NOT_GIVEN
26
+ warn_with_uplevel 'Passing `minor` with the 2nd argument of `App.semantic_version` is deprecated. Use keyword argument like `App.semantic_version(minor: ...)` instead.', uplevel: 1
27
+ minor = legacy_minor
28
+ end
29
+ if legacy_patch != NOT_GIVEN
30
+ warn_with_uplevel 'Passing `patch` with the 3rd argument of `App.semantic_version` is deprecated. Use keyword argument like `App.semantic_version(patch: ...)` instead.', uplevel: 1
31
+ patch = legacy_patch
32
+ end
33
+
19
34
  [major, minor, patch].map { |chunk| sample(Array(chunk)) }.join('.')
20
35
  end
21
36
  end
@@ -5,7 +5,30 @@ module Faker
5
5
  class << self
6
6
  SUPPORTED_FORMATS = %w[png jpg bmp].freeze
7
7
 
8
- def image(slug: nil, size: '300x300', format: 'png', set: 'set1', bgset: nil)
8
+ # rubocop:disable Metrics/ParameterLists
9
+ def image(legacy_slug = NOT_GIVEN, legacy_size = NOT_GIVEN, legacy_format = NOT_GIVEN, legacy_set = NOT_GIVEN, legacy_bgset = NOT_GIVEN, slug: nil, size: '300x300', format: 'png', set: 'set1', bgset: nil)
10
+ # rubocop:enable Metrics/ParameterLists
11
+ if legacy_slug != NOT_GIVEN
12
+ warn_with_uplevel 'Passing `slug` with the 1st argument of `Avatar.image` is deprecated. Use keyword argument like `Avatar.image(slug: ...)` instead.', uplevel: 1
13
+ slug = legacy_slug
14
+ end
15
+ if legacy_size != NOT_GIVEN
16
+ warn_with_uplevel 'Passing `size` with the 2nd argument of `Avatar.image` is deprecated. Use keyword argument like `Avatar.image(size: ...)` instead.', uplevel: 1
17
+ size = legacy_size
18
+ end
19
+ if legacy_format != NOT_GIVEN
20
+ warn_with_uplevel 'Passing `format` with the 3rd argument of `Avatar.image` is deprecated. Use keyword argument like `Avatar.image(format: ...)` instead.', uplevel: 1
21
+ format = legacy_format
22
+ end
23
+ if legacy_set != NOT_GIVEN
24
+ warn_with_uplevel 'Passing `set` with the 4th argument of `Avatar.image` is deprecated. Use keyword argument like `Avatar.image(set: ...)` instead.', uplevel: 1
25
+ set = legacy_set
26
+ end
27
+ if legacy_bgset != NOT_GIVEN
28
+ warn_with_uplevel 'Passing `bgset` with the 5th argument of `Avatar.image` is deprecated. Use keyword argument like `Avatar.image(bgset: ...)` instead.', uplevel: 1
29
+ bgset = legacy_bgset
30
+ end
31
+
9
32
  raise ArgumentError, 'Size should be specified in format 300x300' unless size =~ /^[0-9]+x[0-9]+$/
10
33
  raise ArgumentError, "Supported formats are #{SUPPORTED_FORMATS.join(', ')}" unless SUPPORTED_FORMATS.include?(format)
11
34