fakeit 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 727b95e51aed4489946200aac98d814fe6132e0fe7857819b85e3f48d2f6ab40
4
- data.tar.gz: f3a78ca7afd4782f7003cdd3b888e334e60ea8edfd59b1fec058c822cd72ca6a
3
+ metadata.gz: 46f41bf28d7b4e0775fe84baa2d134947daa0e1ab114c4ad92bc95f63dc678be
4
+ data.tar.gz: ba497fcaf61e251e0316f7ac86223d84550f0c74d35db9319d3b152061de557b
5
5
  SHA512:
6
- metadata.gz: 60bd99ceff20e1ee73843901d6ba5b29955f044092162428736ca093b4f32557c5de755eae435c98d0488fd40997d5c420fac6c067635191b0074cc23a7b09c1
7
- data.tar.gz: b549806af5f29b2284023a637bf79f3cb770a9ca449f3079d5be5c997bccaa4d4fc41efe607258f96b7b6d487eeb6f8fd47ef1c383f2aa3a45f82920397fdf3d
6
+ metadata.gz: b7579ea64592fb2106a6a4af5d747f49be9eca739410a0decc0efb97fab22813a59cf416b57f13cfbc3ae0487449e7e1a5350533c98581baaa078d2266e80689
7
+ data.tar.gz: 42f1b09134e6f67cd933df04c00f9a154888830f500fd4d78a68bef780721d8f70f0409ee1a4d756640f5505783b2539d5856759f9096ff844fba5a023fdc843
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fakeit (0.2.0)
4
+ fakeit (0.2.1)
5
5
  faker (~> 1.9)
6
6
  openapi_parser (= 0.3.1)
7
7
  rack (~> 2.0)
@@ -21,11 +21,11 @@ The following Openapi properties are supported in random response generation
21
21
  | |minLength|Default: `0`|
22
22
  | |maxLength|Default: `minLength + 10`|
23
23
  |integer|enum| |
24
- | |minimum|Default: `1`|
25
- | |maximum|Default: `2^32`|
24
+ | |minimum|Default: `-2^31`|
25
+ | |maximum|Default: `2^31 - 1`|
26
26
  | |exclusiveMinimum| |
27
27
  | |exclusiveMaximum| |
28
28
  | |multipleOf| |
29
- |number|minimum|Default: `0.0`|
30
- | |maximum|Default: `2^32`|
29
+ |number|minimum|Default: `-2^31`|
30
+ | |maximum|Default: `2^31 - 1`|
31
31
  | |multipleOf| |
@@ -19,11 +19,11 @@ Static value generation rule
19
19
  | |format=date-time|midnight today|
20
20
  | |minLength|`1` repeats for (minLength + 10) times if no maxLength specified|
21
21
  | |maxLength|`1` repeats for maxLength times|
22
- |integer|N/A|`1`|
22
+ |integer|N/A|`2^31 - 1`|
23
23
  | |enum|first item|
24
- | |minimum|minimum|
25
- | |exclusiveMinimum|minimum + 1|
26
- | |multipleOf|minimum value meets multipleOf condition|
27
- |number|N/A|0.0|
28
- | |minimum|minimum rounded to 2 decimal places|
29
- | |multipleOf|minimum value meets multipleOf condition|
24
+ | |maximum|maximum|
25
+ | |exclusiveMaximum|maximum - 1|
26
+ | |multipleOf|maximum value meets multipleOf condition|
27
+ |number|N/A|`2^31 - 1`|
28
+ | |maximum|maximum rounded to 2 decimal places|
29
+ | |multipleOf|maximum value meets multipleOf condition|
@@ -1,8 +1,6 @@
1
1
  module Fakeit
2
2
  module Openapi
3
3
  module Example
4
- BIG_INT = 2**32
5
-
6
4
  def integer_example(example_options)
7
5
  example_options[:static] ? static_integer_example : random_integer_example
8
6
  end
@@ -13,7 +11,7 @@ module Fakeit
13
11
  if enum
14
12
  enum.to_a.first
15
13
  else
16
- int_rand_begin * int_multiple
14
+ int_rand_end * int_multiple
17
15
  end
18
16
  end
19
17
 
@@ -45,7 +43,7 @@ module Fakeit
45
43
  if minimum
46
44
  exclusiveMinimum ? minimum + 1 : minimum
47
45
  else
48
- 1
46
+ -2**(int_bits - 1)
49
47
  end
50
48
  end
51
49
 
@@ -53,9 +51,13 @@ module Fakeit
53
51
  if maximum
54
52
  exclusiveMaximum ? maximum - 1 : maximum
55
53
  else
56
- BIG_INT
54
+ 2**(int_bits - 1) - 1
57
55
  end
58
56
  end
57
+
58
+ def int_bits
59
+ (format || 'int32')[/\d+/].to_i
60
+ end
59
61
  end
60
62
  end
61
63
  end
@@ -1,7 +1,8 @@
1
1
  module Fakeit
2
2
  module Openapi
3
3
  module Example
4
- BIG_NUM = 2**32
4
+ MIN_NUM = -2**31
5
+ MAX_NUM = 2**31 - 1
5
6
 
6
7
  def number_example(example_options)
7
8
  example_options[:static] ? static_number_example : random_number_example
@@ -10,7 +11,7 @@ module Fakeit
10
11
  private
11
12
 
12
13
  def static_number_example
13
- (num_rand_begin * num_multiple)
14
+ (num_rand_end * num_multiple)
14
15
  .then { |result| multipleOf ? result : result.round(2) }
15
16
  end
16
17
 
@@ -32,11 +33,11 @@ module Fakeit
32
33
  end
33
34
 
34
35
  def min_num
35
- (minimum || 0).to_f.ceil(2)
36
+ (minimum || MIN_NUM).to_f.ceil(2)
36
37
  end
37
38
 
38
39
  def max_num
39
- (maximum || BIG_NUM).to_f.floor(2)
40
+ (maximum || MAX_NUM).to_f.floor(2)
40
41
  end
41
42
  end
42
43
  end
@@ -16,7 +16,7 @@ module Fakeit
16
16
  case File.extname(src)
17
17
  when '.json' then
18
18
  JSON.method(:parse)
19
- when '.yml' then
19
+ when '.yml', '.yaml' then
20
20
  YAML.method(:safe_load)
21
21
  else
22
22
  raise 'Invalid openapi specification file'
@@ -1,3 +1,3 @@
1
1
  module Fakeit
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.2.1'.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.2.0
4
+ version: 0.2.1
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-07-17 00:00:00.000000000 Z
11
+ date: 2019-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler