faker 2.1.2 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -0
- data/README.md +2 -2
- data/lib/faker.rb +22 -1
- data/lib/faker/books/dune.rb +12 -2
- data/lib/faker/books/lovecraft.rb +54 -7
- data/lib/faker/default/address.rb +30 -5
- data/lib/faker/default/alphanumeric.rb +45 -7
- data/lib/faker/default/app.rb +16 -1
- data/lib/faker/default/avatar.rb +24 -1
- data/lib/faker/default/bank.rb +12 -2
- data/lib/faker/default/boolean.rb +6 -1
- data/lib/faker/default/chile_rut.rb +20 -2
- data/lib/faker/default/code.rb +22 -3
- data/lib/faker/default/commerce.rb +26 -3
- data/lib/faker/default/company.rb +12 -2
- data/lib/faker/default/crypto_coin.rb +18 -3
- data/lib/faker/default/date.rb +48 -5
- data/lib/faker/default/demographic.rb +6 -1
- data/lib/faker/default/driving_licence.rb +20 -4
- data/lib/faker/default/file.rb +36 -2
- data/lib/faker/default/fillmurray.rb +16 -1
- data/lib/faker/default/finance.rb +6 -1
- data/lib/faker/default/hipster.rb +78 -6
- data/lib/faker/default/id_number.rb +12 -2
- data/lib/faker/default/internet.rb +124 -13
- data/lib/faker/default/invoice.rb +22 -3
- data/lib/faker/default/json.rb +26 -2
- data/lib/faker/default/lorem.rb +120 -10
- data/lib/faker/default/lorem_flickr.rb +69 -5
- data/lib/faker/default/lorem_pixel.rb +26 -1
- data/lib/faker/default/markdown.rb +10 -1
- data/lib/faker/default/measurement.rb +48 -8
- data/lib/faker/default/name.rb +6 -1
- data/lib/faker/default/nhs.rb +6 -1
- data/lib/faker/default/number.rb +80 -10
- data/lib/faker/default/omniauth.rb +84 -5
- data/lib/faker/default/phone_number.rb +6 -1
- data/lib/faker/default/placeholdit.rb +24 -1
- data/lib/faker/default/relationship.rb +6 -1
- data/lib/faker/default/source.rb +22 -3
- data/lib/faker/default/string.rb +6 -1
- data/lib/faker/default/stripe.rb +24 -4
- data/lib/faker/default/time.rb +68 -4
- data/lib/faker/default/twitter.rb +26 -3
- data/lib/faker/default/types.rb +38 -5
- data/lib/faker/default/vehicle.rb +22 -3
- data/lib/faker/default/world_cup.rb +16 -2
- data/lib/faker/games/dota.rb +6 -1
- data/lib/faker/movies/star_wars.rb +6 -1
- data/lib/faker/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5418dffd55790eef60544cb4f16a808e2086aa14680099d792b3ad27ea033c76
|
4
|
+
data.tar.gz: d3e1fc21fd5a9ad4645dc53d06304ac95a1b13c8365bee986548e2e2da501c6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42183c4e7030a8a3fdc0a9141493164e2a20c8fb5a54011aea0cb819225b958269ce6477b72d9403f6dcd73bf2b9010c9bd3744053778b05bc104ca2649f3aa7
|
7
|
+
data.tar.gz: e305fbd4a0537ec320dc5645a5e9246811200f5dcec88c4b2799c07a5772743d197edc17c6b9fa29f3316a201bae9b2d3a220ed748a4ede634ba87dc5a0ee4b8
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,29 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [v2.2.0](https://github.com/stympy/faker-ruby/faker/tree/2.2.0) (2019-25-08)
|
4
|
+
|
5
|
+
## Deprecate
|
6
|
+
|
7
|
+
- [PR #1698](https://github.com/stympy/faker/pull/1698) Add warn for positional arguments when using Faker 2.0 [@koic](https://github.com/koic)
|
8
|
+
|
9
|
+
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.
|
10
|
+
|
11
|
+
## Documentation
|
12
|
+
|
13
|
+
- [PR #1688](https://github.com/stympy/faker/pull/1688) Update README install instructions [@EduardoGHdez](https://github.com/EduardoGHdez)
|
14
|
+
- [PR #1689](https://github.com/stympy/faker/pull/1689) Update README.md [@Zeragamba](https://github.com/Zeragamba)
|
15
|
+
- [PR #1690](https://github.com/stympy/faker/pull/1690) Update issue url in PULL_REQUEST_TEMPLATE [@bugtender](https://github.com/bugtender)
|
16
|
+
- [PR #1703](https://github.com/stympy/faker/pull/1703) Return HTTPS URLs from Lorem Flickr [@connorshea](https://github.com/connorshea)
|
17
|
+
|
18
|
+
## Feature Request
|
19
|
+
- [PR #1686](https://github.com/stympy/faker/pull/1686) Update test-unit gem to 3.3.3 [@connorshea](https://github.com/connorshea)
|
20
|
+
|
21
|
+
## Bug/Fixes
|
22
|
+
- [PR #1702](https://github.com/stympy/faker/pull/1702) Fix an argument for test_faker_stripe.rb [@koic](https://github.com/koic)
|
23
|
+
- [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)
|
24
|
+
|
25
|
+
------------------------------------------------------------------------------
|
26
|
+
|
3
27
|
## [v2.1.2](https://github.com/stympy/faker-ruby/faker/tree/2.1.2) (2019-10-08)
|
4
28
|
|
5
29
|
## Enhancements
|
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/
|
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/
|
120
|
+
gem 'faker', :git => 'https://github.com/faker-ruby/faker.git', :branch => 'master'
|
121
121
|
```
|
122
122
|
|
123
123
|
### Default
|
data/lib/faker.rb
CHANGED
@@ -40,9 +40,12 @@ module Faker
|
|
40
40
|
class Base
|
41
41
|
Numbers = Array(0..9)
|
42
42
|
ULetters = Array('A'..'Z')
|
43
|
-
|
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
|
data/lib/faker/books/dune.rb
CHANGED
@@ -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
|
-
|
6
|
-
ALPHABET = ('a'..'z').to_a
|
7
|
-
ALPHANUMS = ALPHABET + (0..9).to_a
|
5
|
+
ALPHANUMS = LLetters + Numbers
|
8
6
|
|
9
|
-
|
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(
|
16
|
+
Array.new(char_count) { sample(self::LLetters) }.join
|
14
17
|
end
|
15
18
|
|
16
|
-
|
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
|
-
|
57
|
+
combined = alphas + numbers + randoms
|
58
|
+
combined.shuffle.join
|
21
59
|
end
|
22
60
|
end
|
23
61
|
end
|
data/lib/faker/default/app.rb
CHANGED
@@ -15,7 +15,22 @@ module Faker
|
|
15
15
|
parse('app.author')
|
16
16
|
end
|
17
17
|
|
18
|
-
|
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
|
data/lib/faker/default/avatar.rb
CHANGED
@@ -5,7 +5,30 @@ module Faker
|
|
5
5
|
class << self
|
6
6
|
SUPPORTED_FORMATS = %w[png jpg bmp].freeze
|
7
7
|
|
8
|
-
|
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
|
|
data/lib/faker/default/bank.rb
CHANGED
@@ -5,7 +5,12 @@ module Faker
|
|
5
5
|
flexible :bank
|
6
6
|
|
7
7
|
class << self
|
8
|
-
def account_number(digits: 10)
|
8
|
+
def account_number(legacy_digits = NOT_GIVEN, digits: 10)
|
9
|
+
if legacy_digits != NOT_GIVEN
|
10
|
+
warn_with_uplevel 'Passing `digits` with the 1st argument of `Bank.account_number` is deprecated. Use keyword argument like `Bank.account_number(digits: ...)` instead.', uplevel: 1
|
11
|
+
digits = legacy_digits
|
12
|
+
end
|
13
|
+
|
9
14
|
output = ''
|
10
15
|
|
11
16
|
output += rand.to_s[2..-1] while output.length < digits
|
@@ -13,10 +18,15 @@ module Faker
|
|
13
18
|
output[0...digits]
|
14
19
|
end
|
15
20
|
|
16
|
-
def iban(country_code: 'GB')
|
21
|
+
def iban(legacy_country_code = NOT_GIVEN, country_code: 'GB')
|
17
22
|
# Each country has it's own format for bank accounts
|
18
23
|
# Many of them use letters in certain parts of the account
|
19
24
|
# Using regex patterns we can create virtually any type of bank account
|
25
|
+
if legacy_country_code != NOT_GIVEN
|
26
|
+
warn_with_uplevel 'Passing `country_code` with the 1st argument of `Bank.iban` is deprecated. Use keyword argument like `Bank.iban(country_code: ...)` instead.', uplevel: 1
|
27
|
+
country_code = legacy_country_code
|
28
|
+
end
|
29
|
+
|
20
30
|
begin
|
21
31
|
pattern = fetch("bank.iban_details.#{country_code.downcase}.bban_pattern")
|
22
32
|
rescue I18n::MissingTranslationData
|