fakeit 0.1.2 → 0.1.3

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: 37c7f01bd53d8fccce9dc5d1411a9917fca097614a2dafe8bd1498cf2f8bd255
4
- data.tar.gz: b35468a6e2daf5749fbedb971026c264e23fe34b6d6a49c322c88cbe48a587de
3
+ metadata.gz: ff6943cf3f6ef0d7cfd9b8801616cc00ce82bd49adb243719ba78c412797bfbc
4
+ data.tar.gz: edce957ddafc77236af8ffd4b956009c6cf5e9a1de3947ebdbf9ada1247896e4
5
5
  SHA512:
6
- metadata.gz: 929e9c035ee1ebce9b5ad833f2b846c1835242d67534a9bec5456369685273cfcb3a7554c89f8802f1592fb66a6098d1e123f9ec90764e0ffba3f1924523e89c
7
- data.tar.gz: eb310158c2228e0ecca7ece315dc12b1e52cad915ef68472c88884d555c05bd42d9b3351a9133d1aa0e52f80c899d4ef759ba9e893eeb5ffd6cce3975eacaf51
6
+ metadata.gz: 61a754086fbfa0735dbdca38180533e0226e20b6f427d92a1961bfd4f2784c19da84f1fcd51de906ec911fa56b949159c6b2f2af556c8aeb48724a6916a303b8
7
+ data.tar.gz: ebf54a1f98ef56275e65139a61a12d12eee120f62a2e3b0ac981ab503ac07ebf2defbf9f27bbd327f4330257ca3088de9e2a08338b06a1519ec71c1255bb929f
data/.rubocop.yml CHANGED
@@ -13,6 +13,7 @@ Metrics/LineLength:
13
13
  Metrics/BlockLength:
14
14
  Exclude:
15
15
  - 'spec/**/*.rb'
16
+ - 'fakeit.gemspec'
16
17
 
17
18
  Security/Open:
18
19
  Enabled: false
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fakeit (0.1.2)
4
+ fakeit (0.1.3)
5
5
  faker (~> 1.9)
6
6
  openapi_parser (= 0.3.0)
7
7
  rack (~> 2.0)
data/README.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # Fakeit
2
2
 
3
- [![CircleCI](https://circleci.com/gh/JustinFeng/fakeit.svg?style=svg)](https://circleci.com/gh/JustinFeng/fakeit)
3
+ [![CircleCI](https://img.shields.io/circleci/build/github/JustinFeng/fakeit.svg)](https://circleci.com/gh/JustinFeng/fakeit)
4
+ [![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability/JustinFeng/fakeit.svg)](https://codeclimate.com/github/JustinFeng/fakeit)
5
+ [![Gem](https://img.shields.io/gem/v/fakeit.svg)](https://rubygems.org/gems/fakeit)
6
+ [![Gem](https://img.shields.io/gem/dt/fakeit.svg)](https://rubygems.org/gems/fakeit)
7
+ [![Docker Pulls](https://img.shields.io/docker/pulls/realfengjia/fakeit.svg)](https://hub.docker.com/r/realfengjia/fakeit)
8
+ [![GitHub](https://img.shields.io/github/license/JustinFeng/fakeit.svg)](https://opensource.org/licenses/MIT)
4
9
 
5
10
  Create mock server from Openapi specification
6
11
 
data/fakeit.gemspec CHANGED
@@ -22,6 +22,8 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = 'fakeit'
23
23
  spec.require_paths = ['lib']
24
24
 
25
+ spec.required_ruby_version = '>= 2.6.0'
26
+
25
27
  spec.add_development_dependency 'bundler', '~> 2.0'
26
28
  spec.add_development_dependency 'byebug', '~> 11.0'
27
29
  spec.add_development_dependency 'rack-test', '~> 1.1'
@@ -4,9 +4,40 @@ module Fakeit
4
4
  MAX_SIZE = 50
5
5
 
6
6
  def array_example(use_example)
7
- Array.new(Faker::Number.between(minItems || 1, maxItems || MAX_SIZE)) do
8
- items.to_example(use_example)
7
+ size = retries = uniqueItems ? min_array : Faker::Number.between(min_array, max_array)
8
+
9
+ generate_items(size, retries, use_example)
10
+ end
11
+
12
+ private
13
+
14
+ def generate_items(size, retries, use_example)
15
+ result = []
16
+
17
+ loop do
18
+ item = items.to_example(use_example)
19
+
20
+ if need_retry?(item, result, retries)
21
+ retries -= 1
22
+ next
23
+ end
24
+
25
+ break if (result << item).size >= size
9
26
  end
27
+
28
+ result
29
+ end
30
+
31
+ def need_retry?(item, result, retries)
32
+ uniqueItems && result.include?(item) && retries.positive?
33
+ end
34
+
35
+ def min_array
36
+ minItems || 1
37
+ end
38
+
39
+ def max_array
40
+ maxItems || MAX_SIZE
10
41
  end
11
42
  end
12
43
  end
@@ -7,12 +7,28 @@ module Fakeit
7
7
  if enum
8
8
  enum.to_a.sample
9
9
  else
10
- Faker::Number.between(min_int, max_int)
10
+ Faker::Number.between(int_rand_begin, int_rand_end) * int_multiple
11
11
  end
12
12
  end
13
13
 
14
14
  private
15
15
 
16
+ def int_rand_begin
17
+ min_int / int_multiple + int_rand_begin_adjust
18
+ end
19
+
20
+ def int_rand_end
21
+ max_int / int_multiple
22
+ end
23
+
24
+ def int_rand_begin_adjust
25
+ (min_int % int_multiple).zero? ? 0 : 1
26
+ end
27
+
28
+ def int_multiple
29
+ multipleOf || 1
30
+ end
31
+
16
32
  def min_int
17
33
  if minimum
18
34
  exclusiveMinimum ? minimum + 1 : minimum
@@ -4,11 +4,23 @@ module Fakeit
4
4
  BIG_NUM = 2**32
5
5
 
6
6
  def number_example
7
- Faker::Number.between(min_num, max_num).round(2)
7
+ (Faker::Number.between(num_rand_begin, num_rand_end) * num_multiple).round(2)
8
8
  end
9
9
 
10
10
  private
11
11
 
12
+ def num_rand_begin
13
+ multipleOf ? (min_num / multipleOf).ceil : min_num
14
+ end
15
+
16
+ def num_rand_end
17
+ multipleOf ? (max_num / multipleOf).floor : max_num
18
+ end
19
+
20
+ def num_multiple
21
+ multipleOf || 1
22
+ end
23
+
12
24
  def min_num
13
25
  (minimum || 0).to_f.ceil(2)
14
26
  end
@@ -1,3 +1,3 @@
1
1
  module Fakeit
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.1.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fakeit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Feng
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-05 00:00:00.000000000 Z
11
+ date: 2019-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -214,7 +214,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
214
214
  requirements:
215
215
  - - ">="
216
216
  - !ruby/object:Gem::Version
217
- version: '0'
217
+ version: 2.6.0
218
218
  required_rubygems_version: !ruby/object:Gem::Requirement
219
219
  requirements:
220
220
  - - ">="