stubify 0.1.1 → 0.1.2
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 +4 -4
- data/README.md +0 -6
- data/lib/stubify.rb +10 -2
- data/lib/stubify/io.rb +8 -1
- data/lib/stubify/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6608cf445c08d76e4a0e786a72d5edf93a027a1
|
4
|
+
data.tar.gz: c293698b5070df62f1f0bf70e56892881ff1564f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
```
|
data/lib/stubify.rb
CHANGED
@@ -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
|
data/lib/stubify/io.rb
CHANGED
@@ -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?
|
data/lib/stubify/version.rb
CHANGED