artirix_data_models 0.14.2 → 0.15.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 +4 -4
- data/README.md +19 -0
- data/lib/artirix_data_models/daos/basic_model_dao.rb +36 -8
- data/lib/artirix_data_models/gateways/data_gateway.rb +18 -17
- data/lib/artirix_data_models/spec_support/gateway_mock.rb +6 -6
- data/lib/artirix_data_models/spec_support/shared_examples/an_artirix_data_model_dao.rb +2 -2
- data/lib/artirix_data_models/version.rb +1 -1
- data/spec/artirix_data_models/gateways/data_gateway_spec.rb +23 -0
- data/spec/support/a_finder_enabled_ui_model_dao.rb +1 -1
- data/spec/support/a_search_enabled_ui_model_dao.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: 51f51b7e92c257a5ff0e8a696329be341af4073e
|
4
|
+
data.tar.gz: 36a9206139840f5587956864af6419b9fdc86511
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68de5e70048bfe05eb6654d4669eb2cfccb09a2c504af5c7cde7e5e1878ec32f18b05d04c05feae9d0106f5a631fe3cf35a3b670d8be54d0bef3da2e20396efb
|
7
|
+
data.tar.gz: 198a1aef72b32cb6bc4a5253ce24faa9f239a4871af7f22a680e87259d65adafa98ca3b1f321ac09ea46e56461aff039aefc24a268cc6535f7da060dbc4954dd
|
data/README.md
CHANGED
@@ -268,6 +268,25 @@ end
|
|
268
268
|
|
269
269
|
## Changes
|
270
270
|
|
271
|
+
### 0.15.0
|
272
|
+
- `Gateway` `perform` and `connect` now accept the extra arguments as keyword arguments:
|
273
|
+
|
274
|
+
```ruby
|
275
|
+
gateway.perform :get, path: '/this/is/required' body: nil, json_body: true, timeout: 10
|
276
|
+
```
|
277
|
+
|
278
|
+
The internals are adapted but if a client app was mocking Gateway's `perform` directly, this could be a breaking change.
|
279
|
+
- added the `timeout` option to perform gateway (and DAO methods). It will add timeout to the Faraday request
|
280
|
+
|
281
|
+
```ruby
|
282
|
+
def connect(method, path:, body: nil, json_body: true, timeout: nil)
|
283
|
+
connection.send(method, path) do |req|
|
284
|
+
req.options.timeout = timeout if timeout.present?
|
285
|
+
# ...
|
286
|
+
end
|
287
|
+
end
|
288
|
+
```
|
289
|
+
|
271
290
|
### 0.14.2
|
272
291
|
- Cache service: expire_cache now can receive options `add_wildcard` and `add_prefix` (both `true` by default), that will control the modifications on the given pattern
|
273
292
|
|
@@ -139,29 +139,57 @@ class ArtirixDataModels::BasicModelDAO
|
|
139
139
|
# PERFORM CALLS #
|
140
140
|
#################
|
141
141
|
|
142
|
-
def perform_get(path, response_adaptor: nil, body: nil, fake_response: nil, cache_adaptor: nil, gateway: nil)
|
142
|
+
def perform_get(path, response_adaptor: nil, body: nil, fake_response: nil, cache_adaptor: nil, timeout: nil, gateway: nil)
|
143
143
|
g = gateway.presence || preloaded_gateway
|
144
144
|
raise_no_gateway unless g.present?
|
145
|
-
|
145
|
+
|
146
|
+
g.get path,
|
147
|
+
response_adaptor: response_adaptor,
|
148
|
+
body: body,
|
149
|
+
timeout: timeout,
|
150
|
+
fake: fake?,
|
151
|
+
fake_response: fake_response,
|
152
|
+
cache_adaptor: cache_adaptor
|
146
153
|
end
|
147
154
|
|
148
155
|
|
149
|
-
def perform_post(path, response_adaptor: nil, body: nil, fake_response: nil, cache_adaptor: nil, gateway: nil)
|
156
|
+
def perform_post(path, response_adaptor: nil, body: nil, fake_response: nil, cache_adaptor: nil, timeout: nil, gateway: nil)
|
150
157
|
g = gateway.presence || preloaded_gateway
|
151
158
|
raise_no_gateway unless g.present?
|
152
|
-
|
159
|
+
|
160
|
+
g.post path,
|
161
|
+
response_adaptor: response_adaptor,
|
162
|
+
body: body,
|
163
|
+
timeout: timeout,
|
164
|
+
fake: fake?,
|
165
|
+
fake_response: fake_response,
|
166
|
+
cache_adaptor: cache_adaptor
|
153
167
|
end
|
154
168
|
|
155
|
-
def perform_put(path, response_adaptor: nil, body: nil, fake_response: nil, cache_adaptor: nil, gateway: nil)
|
169
|
+
def perform_put(path, response_adaptor: nil, body: nil, fake_response: nil, cache_adaptor: nil, timeout: nil, gateway: nil)
|
156
170
|
g = gateway.presence || preloaded_gateway
|
157
171
|
raise_no_gateway unless g.present?
|
158
|
-
|
172
|
+
|
173
|
+
g.put path,
|
174
|
+
response_adaptor: response_adaptor,
|
175
|
+
body: body,
|
176
|
+
timeout: timeout,
|
177
|
+
fake: fake?,
|
178
|
+
fake_response: fake_response,
|
179
|
+
cache_adaptor: cache_adaptor
|
159
180
|
end
|
160
181
|
|
161
|
-
def perform_delete(path, response_adaptor: nil, body: nil, fake_response: nil, cache_adaptor: nil, gateway: nil)
|
182
|
+
def perform_delete(path, response_adaptor: nil, body: nil, fake_response: nil, cache_adaptor: nil, timeout: nil, gateway: nil)
|
162
183
|
g = gateway.presence || preloaded_gateway
|
163
184
|
raise_no_gateway unless g.present?
|
164
|
-
|
185
|
+
|
186
|
+
g.delete path,
|
187
|
+
response_adaptor: response_adaptor,
|
188
|
+
body: body,
|
189
|
+
timeout: timeout,
|
190
|
+
fake: fake?,
|
191
|
+
fake_response: fake_response,
|
192
|
+
cache_adaptor: cache_adaptor
|
165
193
|
end
|
166
194
|
|
167
195
|
# old names
|
@@ -22,13 +22,13 @@ class ArtirixDataModels::DataGateway
|
|
22
22
|
call :delete, path, **opts
|
23
23
|
end
|
24
24
|
|
25
|
-
def call(method, path, json_body: true, response_adaptor: nil, body: nil, fake: false, fake_response: nil, cache_adaptor: nil, **_ignored_options)
|
25
|
+
def call(method, path, json_body: true, response_adaptor: nil, body: nil, fake: false, fake_response: nil, cache_adaptor: nil, timeout: nil, **_ignored_options)
|
26
26
|
if fake
|
27
27
|
result = fake_response.respond_to?(:call) ? fake_response.call : fake_response
|
28
28
|
elsif cache_adaptor.present?
|
29
|
-
result = cache_adaptor.call { perform(method, path, body, json_body) }
|
29
|
+
result = cache_adaptor.call { perform(method, path: path, body: body, json_body: json_body, timeout: timeout) }
|
30
30
|
else
|
31
|
-
result = perform(method, path, body, json_body)
|
31
|
+
result = perform(method, path: path, body: body, json_body: json_body, timeout: timeout)
|
32
32
|
end
|
33
33
|
|
34
34
|
parse_response result: result,
|
@@ -39,31 +39,32 @@ class ArtirixDataModels::DataGateway
|
|
39
39
|
|
40
40
|
private
|
41
41
|
|
42
|
-
def perform_get(path,
|
43
|
-
perform :get, path
|
42
|
+
def perform_get(path, **opts)
|
43
|
+
perform :get, path: path, **opts
|
44
44
|
end
|
45
45
|
|
46
|
-
def perform_post(path,
|
47
|
-
perform :post, path
|
46
|
+
def perform_post(path, **opts)
|
47
|
+
perform :post, path: path, **opts
|
48
48
|
end
|
49
49
|
|
50
|
-
def perform_put(path,
|
51
|
-
perform :put, path
|
50
|
+
def perform_put(path, **opts)
|
51
|
+
perform :put, path: path, **opts
|
52
52
|
end
|
53
53
|
|
54
|
-
def perform_delete(path,
|
55
|
-
perform :delete, path
|
54
|
+
def perform_delete(path, **opts)
|
55
|
+
perform :delete, path: path, **opts
|
56
56
|
end
|
57
57
|
|
58
|
-
def perform(method, path
|
59
|
-
response = connect(method, path, body, json_body)
|
58
|
+
def perform(method, path:, body: nil, json_body: true, timeout: nil)
|
59
|
+
response = connect(method, path: path, body: body, json_body: json_body, timeout: timeout)
|
60
60
|
treat_response(response, method, path)
|
61
61
|
end
|
62
62
|
|
63
|
-
def connect(method, path
|
64
|
-
# binding.pry if method == :delete
|
63
|
+
def connect(method, path:, body: nil, json_body: true, timeout: nil)
|
65
64
|
connection.send(method, path) do |req|
|
66
|
-
|
65
|
+
|
66
|
+
req.options.timeout = timeout if timeout.present?
|
67
|
+
|
67
68
|
unless body.nil?
|
68
69
|
if json_body
|
69
70
|
req.body = body_to_json body
|
@@ -73,7 +74,7 @@ class ArtirixDataModels::DataGateway
|
|
73
74
|
end
|
74
75
|
end
|
75
76
|
end
|
76
|
-
rescue Faraday::ConnectionFailed => e
|
77
|
+
rescue Faraday::ConnectionFailed, Faraday::Error::TimeoutError, Errno::ETIMEDOUT => e
|
77
78
|
raise ConnectionError,
|
78
79
|
path: path,
|
79
80
|
method: method,
|
@@ -12,25 +12,25 @@ def given_gateway_config(connection_url = nil)
|
|
12
12
|
end
|
13
13
|
|
14
14
|
|
15
|
-
def mock_gateway_response(response:, method:, path:, body: nil, json_body: true, gateway: nil)
|
15
|
+
def mock_gateway_response(response:, method:, path:, body: nil, json_body: true, timeout: nil, gateway: nil)
|
16
16
|
gateway ||= ArtirixDataModels::DAORegistry.gateway
|
17
|
-
allow(gateway).to receive(:perform).with(method, path, body, json_body).and_return response
|
17
|
+
allow(gateway).to receive(:perform).with(method, path: path, body: body, json_body: json_body, timeout: timeout).and_return response
|
18
18
|
|
19
19
|
# check with body already parsed
|
20
20
|
unless body.nil?
|
21
21
|
body = body.kind_of?(String) ? body : body.to_json
|
22
|
-
allow(gateway).to receive(:perform).with(method, path, body, json_body).and_return response
|
22
|
+
allow(gateway).to receive(:perform).with(method, path: path, body: body, json_body: json_body, timeout: timeout).and_return response
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
def mock_gateway_not_found_response(method:, path:, body: nil, json_body: true, gateway: nil)
|
26
|
+
def mock_gateway_not_found_response(method:, path:, body: nil, json_body: true, timeout: nil, gateway: nil)
|
27
27
|
gateway ||= ArtirixDataModels::DAORegistry.gateway
|
28
|
-
allow(gateway).to receive(:perform).with(method, path, body, json_body).and_raise ArtirixDataModels::DataGateway::NotFound
|
28
|
+
allow(gateway).to receive(:perform).with(method, path: path, body: body, json_body: json_body, timeout: timeout).and_raise ArtirixDataModels::DataGateway::NotFound
|
29
29
|
|
30
30
|
# check with body already parsed
|
31
31
|
unless body.nil?
|
32
32
|
body = body.kind_of?(String) ? body : body.to_json
|
33
|
-
allow(gateway).to receive(:perform).with(method, path, body, json_body).and_raise ArtirixDataModels::DataGateway::NotFound
|
33
|
+
allow(gateway).to receive(:perform).with(method, path: path, body: body, json_body: json_body, timeout: timeout).and_raise ArtirixDataModels::DataGateway::NotFound
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -43,8 +43,8 @@ shared_examples_for 'an ArtirixDataModel DAO' do
|
|
43
43
|
# mock gateway calls
|
44
44
|
Given(:gateway) do
|
45
45
|
ArtirixDataModels::DataGateway.new.tap do |gateway|
|
46
|
-
expect(gateway).to receive(:perform).with(:get, path_full, nil, true).and_return(json_full).at_most(:once)
|
47
|
-
expect(gateway).to receive(:perform).with(:get, path_partial, nil, true).and_return(json_partial).at_most(:once)
|
46
|
+
expect(gateway).to receive(:perform).with(:get, path: path_full, body: nil, json_body: true, timeout: nil).and_return(json_full).at_most(:once)
|
47
|
+
expect(gateway).to receive(:perform).with(:get, path: path_partial, body: nil, json_body: true, timeout: nil).and_return(json_partial).at_most(:once)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -43,6 +43,29 @@ RSpec.describe ArtirixDataModels::DataGateway, type: :model do
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
+
context 'requests with timeout' do
|
47
|
+
Given(:connection_url) { 'http://10.255.255.1' }
|
48
|
+
Given(:connection) do
|
49
|
+
Faraday.new(url: connection_url, request: { params_encoder: Faraday::FlatParamsEncoder }) do |faraday|
|
50
|
+
faraday.request :url_encoded # form-encode without body only path params
|
51
|
+
faraday.response :logger # log requests to STDOUT
|
52
|
+
faraday.adapter Faraday.default_adapter
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
Given(:gateway) do
|
57
|
+
described_class.new connection: connection
|
58
|
+
end
|
59
|
+
|
60
|
+
Given(:path_with_timeout) { '/anywhere' }
|
61
|
+
|
62
|
+
describe '#get' do
|
63
|
+
When(:result) { gateway.get path_with_timeout, timeout: 1 }
|
64
|
+
|
65
|
+
Then { result == Failure(ArtirixDataModels::DataGateway::ConnectionError) }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
46
69
|
context 'requests' do
|
47
70
|
Given(:connection_url) { 'http://example.com' }
|
48
71
|
Given(:connection_stubs) { Faraday::Adapter::Test::Stubs.new }
|
@@ -19,7 +19,7 @@ shared_examples_for 'a finder enabled UI ModelDAO' do
|
|
19
19
|
# mock gateway calls
|
20
20
|
Given(:gateway) do
|
21
21
|
ArtirixDataModels::DataGateway.new.tap do |gateway|
|
22
|
-
expect(gateway).to receive(:perform).with(:get, path_for_find_by, nil, true).and_return(json_find_by).at_most(:once)
|
22
|
+
expect(gateway).to receive(:perform).with(:get, path: path_for_find_by, body: nil, json_body: true, timeout: nil).and_return(json_find_by).at_most(:once)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -23,7 +23,7 @@ shared_examples_for 'a search enabled UI ModelDAO' do
|
|
23
23
|
# mock gateway calls
|
24
24
|
Given(:gateway) do
|
25
25
|
ArtirixDataModels::DataGateway.new.tap do |gateway|
|
26
|
-
expect(gateway).to receive(:perform).with(:get, path_for_search, nil, true).and_return(json_search).at_most(:once)
|
26
|
+
expect(gateway).to receive(:perform).with(:get, path: path_for_search, body: nil, json_body: true, timeout: nil).and_return(json_search).at_most(:once)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|