feiku 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f227cd25f21a1709c6e91c446a429b62b36658f5912580c16429b9bf8aea0d7
4
- data.tar.gz: da7a4061a2dd6a9ead60636ea8a0f854134eb9febad5d195d14cde5a5dfa31d2
3
+ metadata.gz: 3297b4de9084be2ec8060291c0e38b91b3b23a99408f31db1df9f216e547b01d
4
+ data.tar.gz: 206266a45fc4dd2da0b6ac92b2a508c1cc9698fa77c5c5d4e0f5ee386614fee4
5
5
  SHA512:
6
- metadata.gz: 9e0bb0c959fc83b5ce0058fc2e3fb7d1d20e9039c245aabdbdae8b1d3bfafb3bace97e1b5a91b34b1bbb54b5cb5f59e88a8807e26f6e8f4719a03124f79113a6
7
- data.tar.gz: a96c904d364a4bfa518cdf3a7ab958bf5d663d80e3275e3d1f1724a9c4bb8b50192268952da8c09d50347d7636f0707a59456153baddfbf655cd7659052f3406
6
+ metadata.gz: be412a317663c1229e1d4ba42473934d8742ecaade40fff46dae6fdf8da7ea884a34cac1df0b80c07a63fc41abb2710e8559eb18e3f1b2ccd2fa4f3b942295a1
7
+ data.tar.gz: 33cb68c3f37854435e28d50ad4fa279971faf125590e3a4bf1a59c12b097df271eac43eba73501b588bf01170c04828c709972553ceeb95e46fc136a1f80c2ee
data/CHANGELOG.md CHANGED
@@ -3,3 +3,7 @@
3
3
  ## [0.1.0] - 2024-08-23
4
4
 
5
5
  - Initial release
6
+
7
+ ## [0.1.1] 2024-09-19
8
+
9
+ - Fix the case where real emails are generated
data/README.md CHANGED
@@ -10,15 +10,13 @@ Also, while they provide tons of preset data, they don't provide a feature to en
10
10
 
11
11
  ## Installation
12
12
 
13
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
14
-
15
13
  Install the gem and add to the application's Gemfile by executing:
16
14
 
17
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
15
+ $ bundle add feiku
18
16
 
19
17
  If bundler is not being used to manage dependencies, install the gem by executing:
20
18
 
21
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
19
+ $ gem install feiku
22
20
 
23
21
  ## Usage
24
22
 
@@ -1,5 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ using(Module.new do
4
+ refine Array do
5
+ alias_method :generate, :sample
6
+ end
7
+ end)
8
+
3
9
  module Feiku
4
10
  # Generator is a behind-scene class that generates fake data
5
11
  class Generator
@@ -29,7 +35,7 @@ module Feiku
29
35
  length = @length.is_a?(Integer) ? @length : @length.to_a.sample
30
36
  self.class.const_get("RANDOM_#{@value.to_s.upcase}").sample(length).join
31
37
  end
32
- when Hash then @value.transform_values(&:sample)
38
+ when Hash then @value.transform_values(&:generate)
33
39
  else raise
34
40
  end
35
41
  @format % @fillings
data/lib/feiku/unit.rb ADDED
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "securerandom"
4
+
5
+ module Feiku
6
+ # Basic unit for generating fake data
7
+ class Unit
8
+ RANDOM_STRING = [*"a".."z", *"A".."Z"].freeze
9
+
10
+ def initialize(data_type: nil, length: nil)
11
+ @data_type = data_type
12
+ @length = length
13
+ @unique = false
14
+ end
15
+
16
+ def generate(max_attempt: 10, &block)
17
+ length = @length.is_a?(Integer) ? @length : @length.to_a.sample
18
+ generated = _generate(length)
19
+ return generated if check_success_with(generated, block) && check_uniqueness(generated)
20
+
21
+ attempt_count = 0
22
+ while attempt_count <= max_attempt
23
+ item = _generate(length)
24
+ return item if check_success_with(item) && check_uniqueness(item)
25
+ end
26
+ raise Feiku::Error, "Cannot generate correct data within given attempt times: #{max_attempt}"
27
+ end
28
+
29
+ def filter_result(generated, &block)
30
+ generated = _generate(length) until block.call(generated)
31
+ end
32
+
33
+ def unique
34
+ @unique = true
35
+ self
36
+ end
37
+
38
+ private
39
+
40
+ def check_success_with(item, checker)
41
+ return true if checker.nil?
42
+
43
+ checker.call(item)
44
+ end
45
+
46
+ def check_uniqueness(item)
47
+ return true unless @unique
48
+
49
+ # TODO
50
+ item == 42
51
+ end
52
+
53
+ def _generate(length)
54
+ case @data_type
55
+ when :string then Array.new(length) { RANDOM_STRING.sample }.join
56
+ when :alphanumeric then SecureRandom.alphanumeric(length)
57
+ when Proc then @data_type.call(length)
58
+ else raise Feiku::Error
59
+ end
60
+ end
61
+ end
62
+
63
+ Username = Unit.new(data_type: :alphanumeric, length: 2..10)
64
+ end
data/lib/feiku/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Feiku
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/feiku.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "feiku/version"
4
4
  require_relative "feiku/generator"
5
+ require_relative "feiku/unit"
5
6
 
6
7
  # Toplevel
7
8
  module Feiku
@@ -12,5 +13,7 @@ module Feiku
12
13
  end
13
14
  end
14
15
 
15
- Feiku.register(:Email, format: "%<name>ss@%<domain>s",
16
- value: { name: %w[alice bob charlie], domain: %w[gmail.com yahoo.com] })
16
+ Feiku.register(:Domain, format: "%<name>s.example", value: { name: Feiku::Username })
17
+ Feiku.register(:Email,
18
+ format: "%<name>s@%<domain>s",
19
+ value: { name: Feiku::Username, domain: Feiku::Domain })
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feiku
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - OKURA Masafumi
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-09-05 00:00:00.000000000 Z
10
+ date: 2024-09-19 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: Feiku (pronounced as "fake") is a tool to generate fake data. Unlike
14
13
  other solutions, it doesn't use YAML file to define data. Instead, it generates
@@ -27,6 +26,7 @@ files:
27
26
  - Rakefile
28
27
  - lib/feiku.rb
29
28
  - lib/feiku/generator.rb
29
+ - lib/feiku/unit.rb
30
30
  - lib/feiku/version.rb
31
31
  - sig/feiku.rbs
32
32
  homepage: https://github.com/okuramasafumi/feiku
@@ -36,7 +36,6 @@ metadata:
36
36
  homepage_uri: https://github.com/okuramasafumi/feiku
37
37
  source_code_uri: https://github.com/okuramasafumi/feiku
38
38
  changelog_uri: https://github.com/okuramasafumi/feiku/blob/main/CHANGELOG.md
39
- post_install_message:
40
39
  rdoc_options: []
41
40
  require_paths:
42
41
  - lib
@@ -51,8 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
50
  - !ruby/object:Gem::Version
52
51
  version: '0'
53
52
  requirements: []
54
- rubygems_version: 3.5.17
55
- signing_key:
53
+ rubygems_version: 3.6.0.dev
56
54
  specification_version: 4
57
55
  summary: A lightweight fake data generator for Ruby
58
56
  test_files: []