rack-override-path 0.0.1 → 0.0.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/lib/override_path.rb +1 -1
- data/lib/rack/override-path.rb +1 -1
- data/lib/rack/override_path.rb +29 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9bc70648738871efd01b5a306b49345ae9f6648f38e27988e4483556b8af951
|
4
|
+
data.tar.gz: e9a2fab0d5dffeab3285e75bd98cff7a457f805c67ea2255405060b162083a74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2211420a857f9f9d4a76e222353bd1f85e8b32f68f219c83cbc746472dff381d86d933fd7d2588114defb90d7fab040755f09e6638d07b3134885d33945720d1
|
7
|
+
data.tar.gz: d231b967249ab9ae439ad1fce00582c4f7740a098f91e1298e94b72fb9935503d10906fd4fec39db5782b4dfd9a3114131c9c1e23bdc6779a7f6793ca4866c59
|
data/lib/override_path.rb
CHANGED
data/lib/rack/override-path.rb
CHANGED
data/lib/rack/override_path.rb
CHANGED
@@ -22,17 +22,38 @@ module Rack
|
|
22
22
|
override_path(req)
|
23
23
|
elsif path_overridden?(req.path)
|
24
24
|
handle_override(req.path, env)
|
25
|
+
elsif get_overrides?(req)
|
26
|
+
get_overrides(req)
|
25
27
|
else
|
26
28
|
@app.call(env)
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
32
|
+
def get_overrides?(req)
|
33
|
+
req.path == '/override/path' && req.get?
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_overrides(_req)
|
37
|
+
[200, { 'Content-Type' => 'application/json' }, [@overridden_paths.to_json]]
|
38
|
+
end
|
39
|
+
|
30
40
|
def override(path)
|
31
|
-
@overridden_paths.find
|
41
|
+
@overridden_paths.find do |override|
|
42
|
+
override_path = literal_path?(override['path']) ? literal_path(override['path']) : override['path']
|
43
|
+
path.match(Regexp.new(override_path))
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def literal_path?(path)
|
48
|
+
path[0] == '/'
|
49
|
+
end
|
50
|
+
|
51
|
+
def literal_path(path)
|
52
|
+
"^#{path}$"
|
32
53
|
end
|
33
54
|
|
34
55
|
def override_path?(req)
|
35
|
-
req.
|
56
|
+
req.path == '/override/path' && req.post?
|
36
57
|
end
|
37
58
|
|
38
59
|
def override_path(req)
|
@@ -80,8 +101,12 @@ module Rack
|
|
80
101
|
response_status = override['status'] || status || DEFAULT_STATUS
|
81
102
|
response_headers = override['headers'] || headers || DEFAULT_HEADERS
|
82
103
|
response_body = override['body'] || body || DEFAULT_BODY
|
83
|
-
|
84
|
-
|
104
|
+
[response_status, response_headers, prepare_response_body_for_rack(response_body)]
|
105
|
+
end
|
106
|
+
|
107
|
+
def prepare_response_body_for_rack(response_body)
|
108
|
+
response_body = response_body.is_a?(Hash) ? response_body.to_json : response_body
|
109
|
+
response_body.is_a?(Array) ? response_body : [response_body]
|
85
110
|
end
|
86
111
|
|
87
112
|
def request(env)
|