fantasy_faker 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +29 -0
- data/lib/fantasy_faker/unique_generator.rb +35 -0
- data/lib/fantasy_faker/utils/base_module.rb +4 -0
- data/lib/fantasy_faker/version.rb +1 -1
- data/lib/fantasy_faker.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b2564d8293a91c1c0572693b78d0a2d472b9bada33506defd0af70015cb7de5f
|
|
4
|
+
data.tar.gz: '00709549331b1fd21196009a36c9baa8d1c1c497868b5a68320e70b8e5562f30'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dba61364fc29ce55098bc2610f02c5c993faeb348112acbd20b1de42f3a112f60f7fdec2c78d8f3ef4112c7dbd67480fc2d49edfc43622754174fe26dac85acb
|
|
7
|
+
data.tar.gz: 6bb6a69246f54fc860840f45e96d80a3d80f52e55dfaf21b775ae036d2d08e57ef2fc9469d6947e9eee5eaa7b5b6ac44c83fce2d83888833790de6b4f2dc7e77
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.0 - October 24, 2026
|
|
4
|
+
|
|
5
|
+
- Add `.unique` to all character name and nickname generators, with per-method tracking across locale changes.
|
|
6
|
+
- Raise `FantasyFaker::UniqueGenerator::RetryLimitExceeded` after 10,000 unsuccessful attempts to generate a new value.
|
|
7
|
+
- Add `FantasyFaker::Character.unique.clear` to reset uniqueness tracking.
|
|
8
|
+
|
|
3
9
|
## 0.2.0 - October 21, 2026
|
|
4
10
|
|
|
5
11
|
- Expand the first-name dictionaries from 2,499 to 5,040 distinct male names and from 1,380 to 2,795 distinct female names.
|
data/README.md
CHANGED
|
@@ -50,6 +50,35 @@ FantasyFaker.use_locale(:pl) do
|
|
|
50
50
|
end
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
+
### Unique values
|
|
54
|
+
|
|
55
|
+
Use `.unique` with any character generator: `male_first_name`, `female_first_name`,
|
|
56
|
+
`male_nickname`, `female_nickname`, `male_name`, or `female_name`.
|
|
57
|
+
|
|
58
|
+
```ruby
|
|
59
|
+
FantasyFaker::Character.unique.male_name
|
|
60
|
+
FantasyFaker::Character.unique.female_nickname
|
|
61
|
+
|
|
62
|
+
# Reset all character generators' uniqueness history (for example, between tests)
|
|
63
|
+
FantasyFaker::Character.unique.clear
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
In FactoryBot (formerly FactoryGirl), use it inside the attribute block:
|
|
67
|
+
|
|
68
|
+
```ruby
|
|
69
|
+
factory :character do
|
|
70
|
+
name { FantasyFaker::Character.unique.male_name }
|
|
71
|
+
end
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Values are tracked separately for each method within the current Ruby process,
|
|
75
|
+
including across locale changes. Ordinary calls without `.unique` are not tracked.
|
|
76
|
+
This does not check existing database records or coordinate separate processes.
|
|
77
|
+
|
|
78
|
+
If no new value is found after 10,000 attempts, generation raises
|
|
79
|
+
`FantasyFaker::UniqueGenerator::RetryLimitExceeded` rather than returning a duplicate.
|
|
80
|
+
Because generation is random, this can happen before every possible value has been used.
|
|
81
|
+
|
|
53
82
|
## Development
|
|
54
83
|
|
|
55
84
|
Dictionary data is stored in YAML files under `locales/`:
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'set'
|
|
4
|
+
|
|
5
|
+
module FantasyFaker
|
|
6
|
+
class UniqueGenerator
|
|
7
|
+
class RetryLimitExceeded < RuntimeError; end
|
|
8
|
+
|
|
9
|
+
def initialize(generator)
|
|
10
|
+
@generator = generator
|
|
11
|
+
@previous_results = Hash.new { |results, method| results[method] = Set.new }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def clear
|
|
15
|
+
@previous_results.clear
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def method_missing(method, ...)
|
|
21
|
+
return super unless @generator.respond_to?(method)
|
|
22
|
+
|
|
23
|
+
10_000.times do
|
|
24
|
+
result = @generator.public_send(method, ...)
|
|
25
|
+
return result if @previous_results[method].add?(result)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
raise RetryLimitExceeded, "Unable to generate a unique #{method} after 10,000 attempts"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def respond_to_missing?(method, include_private = false)
|
|
32
|
+
@generator.respond_to?(method) || super
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
data/lib/fantasy_faker.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fantasy_faker
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Konrad Jurkowski
|
|
@@ -21,6 +21,7 @@ files:
|
|
|
21
21
|
- README.md
|
|
22
22
|
- lib/fantasy_faker.rb
|
|
23
23
|
- lib/fantasy_faker/character.rb
|
|
24
|
+
- lib/fantasy_faker/unique_generator.rb
|
|
24
25
|
- lib/fantasy_faker/utils/array_utils.rb
|
|
25
26
|
- lib/fantasy_faker/utils/base_module.rb
|
|
26
27
|
- lib/fantasy_faker/version.rb
|