stubify 0.1.1 → 0.1.2

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
  SHA1:
3
- metadata.gz: 6cdf3c98837d99ac32a3638b51ada2857535b84a
4
- data.tar.gz: b42efacd614f1adad54dfeecfbc93077509d9f8c
3
+ metadata.gz: e6608cf445c08d76e4a0e786a72d5edf93a027a1
4
+ data.tar.gz: c293698b5070df62f1f0bf70e56892881ff1564f
5
5
  SHA512:
6
- metadata.gz: e24d36514b3f6f23e2c054300ae8fadfa3575e16a59c841083bff1402b37419cc9177008c12b3641c6d330114dff32e444b0c081cc15edfe750b43a579f0c22c
7
- data.tar.gz: ac125c537db1958ddcfcfa42b4980cb0bab4d4e40e82e77eb871be40dfb87621b6b1662e90ff13598b8bfb3ffee065ed9fca5acd489b59649eca0745f5817852
6
+ metadata.gz: 1df5f1ddb5086430488befda366ebe1ffe60bb297e89c9a61715221f0f8c6bc99781f5465196487d149fd819ba47e80944ce63b919531d746f50db5d62eaa8d5
7
+ data.tar.gz: bd1f256f19e37250e0af0a30e7f1b1fe12b192c863db48c5d2e30d7ab2a42e3af28760d08e826c1aecbd156febe1c08ea673544a6940d8255b88b39d88c68bd0
data/README.md CHANGED
@@ -26,12 +26,6 @@ Next time a request to `http://localhost:4567/rest_api/user/32325` is made the c
26
26
  * Accepts `GET`, `POST`, `PUT` and `DELETE` requests.
27
27
  * HTTP headers, query parameters and request bodies are taken into account.
28
28
 
29
- ## Roadmap
30
-
31
- This is a summary of the ideas which implementation is pending:
32
-
33
- * Whitelisting of endpoints to avoid caching.
34
-
35
29
  ## Installation
36
30
 
37
31
  ```
@@ -18,8 +18,9 @@ module Stubify
18
18
  c.syntax = 'server [options]'
19
19
  c.description = 'Runs a local environment that will forward the requests received to the host provided. Responses will be cached'
20
20
  c.option '--host STRING', String, 'Host the requests will be redirected to. i.e. https://easy-peasy.io'
21
- c.option '--directory DIR', String, 'Path where fixtures will be stored. i.e. fixtures/'
22
21
  c.option '--port STRING', String, 'Port the local environment will listen to. Default is 4567'
22
+ c.option '--directory DIR', String, 'Path where fixtures will be stored. i.e. fixtures/'
23
+ c.option '--whitelist DIR', String, 'Path to the .yaml file with the whitelisted paths'
23
24
  c.option '--verbose', 'Increases the amount of information logged'
24
25
  c.action do |args, options|
25
26
  # Ensure host is set
@@ -31,7 +32,8 @@ module Stubify
31
32
  options.default \
32
33
  port: '4567',
33
34
  directory: 'fixtures',
34
- verbose: false
35
+ verbose: false,
36
+ whitelisted: parse_whitelist(options.whitelist)
35
37
 
36
38
  # Set env variables
37
39
  ENV['PORT'] = options.port
@@ -46,5 +48,11 @@ module Stubify
46
48
  run!
47
49
  end
48
50
 
51
+ def parse_whitelist(file_path)
52
+ require 'yaml'
53
+ return [] unless !file_path.nil? && Pathname.new(file_path).file?
54
+ return YAML.load_file(file_path)
55
+ end
56
+
49
57
  end
50
58
  end
@@ -9,7 +9,6 @@ module Stubify
9
9
 
10
10
  def self.write_on_disk(request, body, response)
11
11
  path = IO.path_from_request(request)
12
- FileUtils.mkdir_p(path)
13
12
  file_name = IO.file_name_from_request(request, body)
14
13
 
15
14
  data = {
@@ -18,6 +17,10 @@ module Stubify
18
17
  'body': response.body.to_s
19
18
  }
20
19
 
20
+ # Do not persist if path is whitelisted
21
+ return data if Stubify.options.whitelisted.include?(request.path)
22
+
23
+ FileUtils.mkdir_p(path)
21
24
  File.open(File.join(path, file_name), "wb") do |file|
22
25
  file.puts(data.to_json)
23
26
  end
@@ -33,6 +36,10 @@ module Stubify
33
36
  end
34
37
 
35
38
  def self.cached?(request, body)
39
+ # Do not load cache if path is whitelisted
40
+ return false if Stubify.options.whitelisted.include?(request.path)
41
+
42
+ # Otherwise check there is a cached payload
36
43
  path = IO.path_from_request(request)
37
44
  file_name = IO.file_name_from_request(request, body)
38
45
  return Pathname.new(File.join(path, file_name)).file?
@@ -1,6 +1,6 @@
1
1
  module Stubify
2
2
 
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  DESCRIPTION = 'Create stub environments the easy way'
5
5
 
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stubify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Vidal