fakeit 0.3.1 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e00b82e5234f7a84b09aa97b54ca9bc6b3d21e180d70d04093cc9abfa70df47b
4
- data.tar.gz: 2d4e588379c5e8d5db03044353c37318388eb3abbc44f1ff8582d29e1fcd70dc
3
+ metadata.gz: 85a4951080b18afc8b31d90df48908395db45187040d55234f2e8d012d7e604b
4
+ data.tar.gz: '038962f3d25cf199b87c45f3e2556fea349ae30939da4a8ea5a67a6fc32c7c47'
5
5
  SHA512:
6
- metadata.gz: b31b1a0365c538bcd89f9a9b61d09477a36a522e2bc12dc88dc71603856c6e9c269aadb378dd83f34f37910fe2b76693a8bb11444306deaf1e54526b306cc294
7
- data.tar.gz: 4db7cb39db416d99e1585a9bb141f803d5f555d7203fa4f4095b587f0d883593c7f9498093b3ba71ec30f6696a219dcb6925e10e18256268d30ddd2e1ab50057
6
+ metadata.gz: 803b450a3aaff3aae4a2a93e99e205076476585ba344febf551a6fadb743f6d44e3c9955179e296530fd0fb37ead6b3f60ebefb825cd5dd0771cb2811e067a68
7
+ data.tar.gz: efc7ba4148e2f557e882c449266f8559eb2208fcd0801157aea4130ec95b42378826d6b932742a1879d1f666be0613e1a699e423e425a4a3afe7cbc5477c2a01
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fakeit (0.3.1)
4
+ fakeit (0.4.0)
5
5
  faker (~> 2.2)
6
6
  openapi_parser (= 0.3.1)
7
7
  rack (~> 2.0)
@@ -17,15 +17,15 @@ GEM
17
17
  concurrent-ruby (1.1.5)
18
18
  diff-lcs (1.3)
19
19
  docile (1.3.2)
20
- faker (2.2.1)
21
- i18n (>= 0.8)
20
+ faker (2.5.0)
21
+ i18n (~> 1.6.0)
22
22
  i18n (1.6.0)
23
23
  concurrent-ruby (~> 1.0)
24
24
  jaro_winkler (1.5.3)
25
25
  json (2.2.0)
26
26
  openapi_parser (0.3.1)
27
- parallel (1.17.0)
28
- parser (2.6.4.0)
27
+ parallel (1.18.0)
28
+ parser (2.6.5.0)
29
29
  ast (~> 2.4.0)
30
30
  rack (2.0.7)
31
31
  rack-cors (1.0.3)
@@ -33,20 +33,20 @@ GEM
33
33
  rack (>= 1.0, < 3)
34
34
  rainbow (3.0.0)
35
35
  rake (12.3.3)
36
- rspec (3.8.0)
37
- rspec-core (~> 3.8.0)
38
- rspec-expectations (~> 3.8.0)
39
- rspec-mocks (~> 3.8.0)
40
- rspec-core (3.8.2)
41
- rspec-support (~> 3.8.0)
42
- rspec-expectations (3.8.4)
36
+ rspec (3.9.0)
37
+ rspec-core (~> 3.9.0)
38
+ rspec-expectations (~> 3.9.0)
39
+ rspec-mocks (~> 3.9.0)
40
+ rspec-core (3.9.0)
41
+ rspec-support (~> 3.9.0)
42
+ rspec-expectations (3.9.0)
43
43
  diff-lcs (>= 1.2.0, < 2.0)
44
- rspec-support (~> 3.8.0)
45
- rspec-mocks (3.8.1)
44
+ rspec-support (~> 3.9.0)
45
+ rspec-mocks (3.9.0)
46
46
  diff-lcs (>= 1.2.0, < 2.0)
47
- rspec-support (~> 3.8.0)
48
- rspec-support (3.8.2)
49
- rubocop (0.74.0)
47
+ rspec-support (~> 3.9.0)
48
+ rspec-support (3.9.0)
49
+ rubocop (0.75.0)
50
50
  jaro_winkler (~> 1.5.1)
51
51
  parallel (~> 1.10)
52
52
  parser (>= 2.6)
@@ -54,7 +54,7 @@ GEM
54
54
  ruby-progressbar (~> 1.7)
55
55
  unicode-display_width (>= 1.4.0, < 1.7)
56
56
  ruby-progressbar (1.10.1)
57
- simplecov (0.17.0)
57
+ simplecov (0.17.1)
58
58
  docile (~> 1.1)
59
59
  json (>= 1.8, < 3)
60
60
  simplecov-html (~> 0.10.0)
data/README.md CHANGED
@@ -33,6 +33,7 @@ After tried several existing options, we cannot find a best solution to meet all
33
33
  * Randomly or statically generated response
34
34
  * Request validation
35
35
  * Load specification from local or remote
36
+ * Support hot reload local specification
36
37
  * Support specification in yaml or json format
37
38
 
38
39
  **Note:** Only support json content type as of now
@@ -2,7 +2,7 @@ module Fakeit
2
2
  module App
3
3
  class << self
4
4
  def create(spec_file, options)
5
- specification = Fakeit::Openapi.load(spec_file)
5
+ specification = Fakeit::Openapi::Specification.new(spec_file)
6
6
 
7
7
  proc do |env|
8
8
  request = Rack::Request.new(env)
@@ -7,7 +7,6 @@ module Fakeit
7
7
  open(src, &:read)
8
8
  .then(&parse_method)
9
9
  .then(&OpenAPIParser.method(:parse))
10
- .then(&Specification.method(:new))
11
10
  end
12
11
 
13
12
  private
@@ -1,15 +1,32 @@
1
1
  module Fakeit
2
2
  module Openapi
3
3
  class Specification
4
- def initialize(doc)
5
- @doc = doc
4
+ def initialize(spec_file)
5
+ @spec_file = spec_file
6
+ @mtime = File.mtime(spec_file) if File.exist?(spec_file)
7
+ @doc = Fakeit::Openapi.load(spec_file)
6
8
  end
7
9
 
8
10
  def operation(method, path, options)
11
+ reload_spec if @mtime
12
+
9
13
  @doc
10
14
  .request_operation(method, path)
11
15
  &.then { |operation| Operation.new(operation, options) }
12
16
  end
17
+
18
+ private
19
+
20
+ def reload_spec
21
+ new_mtime = File.mtime(@spec_file)
22
+
23
+ return if @mtime == new_mtime
24
+
25
+ @mtime = new_mtime
26
+ @doc = Fakeit::Openapi.load(@spec_file)
27
+ rescue StandardError => _e
28
+ Fakeit::Logger.warn(Rainbow('Invalid spec file, use previous snapshot instead').red)
29
+ end
13
30
  end
14
31
  end
15
32
  end
@@ -1,3 +1,3 @@
1
1
  module Fakeit
2
- VERSION = '0.3.1'.freeze
2
+ VERSION = '0.4.0'.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.3.1
4
+ version: 0.4.0
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-09-01 00:00:00.000000000 Z
11
+ date: 2019-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler