lhs 19.0.2 → 19.1.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 +15 -4
- data/lib/lhs/concerns/record/endpoints.rb +0 -12
- data/lib/lhs/version.rb +1 -1
- data/spec/record/endpoint_priorities_spec.rb +26 -0
- metadata +6 -5
- data/spec/record/endpoint_misconfiguration_spec.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fce80cb737ee0b8d0cedfb8d5ff785baf20e468fcb875dcaab3a241861df1253
|
4
|
+
data.tar.gz: 7bd2a65ea111864756de1b9d74063db7865026f47e702a6ba005fa8dead64c3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80bda8a5f669ea96f3a4922a0a0efb69f456b68431cf844fed26392fbc5b8eb0cbab68cc69972226558c05a138290dd226c6c606342685c56d0f1d417481dcb1
|
7
|
+
data.tar.gz: 66bded778c0ad0ad02e71f6a81daa06ed28c640ff94064496d1dea8129200473ce11e658b9c4bcbf462ec5ea2ec5e3d4c4d11e3228218115888b79c4e20b9d19
|
data/README.md
CHANGED
@@ -45,7 +45,7 @@ record.review # "Lunch was great
|
|
45
45
|
* [Record](#record)
|
46
46
|
* [Endpoints](#endpoints)
|
47
47
|
* [Configure endpoint hosts](#configure-endpoint-hosts)
|
48
|
-
* [
|
48
|
+
* [Endpoint priorities](#endpoint-priorities)
|
49
49
|
* [Record inheritance](#record-inheritance)
|
50
50
|
* [Find multiple records](#find-multiple-records)
|
51
51
|
* [fetch](#fetch)
|
@@ -228,9 +228,11 @@ class Record < LHS::Record
|
|
228
228
|
end
|
229
229
|
```
|
230
230
|
|
231
|
-
####
|
231
|
+
#### Endpoint Priorities
|
232
232
|
|
233
|
-
|
233
|
+
LHS uses endpoint configurations to determine what endpoint to use when data is requested, in a similiar way, routes are identified in Rails to map requests to controllers.
|
234
|
+
|
235
|
+
If they are ambiguous, LHS will always use the first one found:
|
234
236
|
|
235
237
|
```ruby
|
236
238
|
# app/models/record.rb
|
@@ -241,9 +243,18 @@ class Record < LHS::Record
|
|
241
243
|
endpoint '{+service}/bananas'
|
242
244
|
|
243
245
|
end
|
246
|
+
```
|
247
|
+
|
248
|
+
```ruby
|
249
|
+
# app/controllers/some_controller.rb
|
244
250
|
|
245
|
-
|
251
|
+
Record.fetch
|
252
|
+
```
|
246
253
|
```
|
254
|
+
GET https://service.example.com/records
|
255
|
+
```
|
256
|
+
|
257
|
+
**Be aware that, if you configure ambigious endpoints accross multiple classes, the order of things is not deteministic. Ambigious endpoints accross multiple classes need to be avoided.**
|
247
258
|
|
248
259
|
### Record inheritance
|
249
260
|
|
@@ -25,7 +25,6 @@ class LHS::Record
|
|
25
25
|
self.endpoints = endpoints.clone
|
26
26
|
validates_deprecation_check!(options)
|
27
27
|
endpoint = LHC::Endpoint.new(url, options)
|
28
|
-
sanity_check(endpoint)
|
29
28
|
endpoints.push(endpoint)
|
30
29
|
LHS::Record::Endpoints.all ||= {}
|
31
30
|
LHS::Record::Endpoints.all[url] = self
|
@@ -50,16 +49,6 @@ class LHS::Record
|
|
50
49
|
endpoint
|
51
50
|
end
|
52
51
|
|
53
|
-
# Prevent ambiguous endpoints
|
54
|
-
def sanity_check(new_endpoint)
|
55
|
-
endpoints.each do |existing_endpoint|
|
56
|
-
invalid = existing_endpoint.placeholders.sort == new_endpoint.placeholders.sort &&
|
57
|
-
existing_endpoint.url != new_endpoint.url
|
58
|
-
next unless invalid
|
59
|
-
raise "Ambiguous endpoints! Cannot differentiate between #{existing_endpoint.url} and #{new_endpoint.url}"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
52
|
# Computes the url from params
|
64
53
|
# by identifiying endpoint and compiles it if necessary.
|
65
54
|
def compute_url!(params)
|
@@ -112,7 +101,6 @@ class LHS::Record
|
|
112
101
|
endpoint.placeholders.length
|
113
102
|
end
|
114
103
|
bases = endpoints[endpoints.keys.min]
|
115
|
-
raise 'Multiple base endpoints found' if bases.count > 1
|
116
104
|
bases.first
|
117
105
|
end
|
118
106
|
end
|
data/lib/lhs/version.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
describe LHS::Record do
|
6
|
+
|
7
|
+
context 'endpoint priorities' do
|
8
|
+
|
9
|
+
before do
|
10
|
+
class Record < LHS::Record
|
11
|
+
endpoint 'https://api/v2/feedbacks'
|
12
|
+
endpoint 'https://api/v2/reviews'
|
13
|
+
endpoint 'https://api/v2/streets/{id}'
|
14
|
+
endpoint 'https://api/v2/feedbacks/{id}'
|
15
|
+
endpoint 'https://api/v2/reviews/{id}'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'always takes the first endpoint found' do
|
20
|
+
stub_request(:get, "https://api/v2/feedbacks").to_return(status: 200)
|
21
|
+
Record.fetch
|
22
|
+
stub_request(:get, "https://api/v2/streets/1").to_return(status: 200)
|
23
|
+
Record.find(1)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lhs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 19.0
|
4
|
+
version: 19.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- https://github.com/local-ch/lhs/graphs/contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -391,8 +391,8 @@ files:
|
|
391
391
|
- spec/record/dig_configuration_spec.rb
|
392
392
|
- spec/record/dup_spec.rb
|
393
393
|
- spec/record/endpoint_inheritance_spec.rb
|
394
|
-
- spec/record/endpoint_misconfiguration_spec.rb
|
395
394
|
- spec/record/endpoint_options_spec.rb
|
395
|
+
- spec/record/endpoint_priorities_spec.rb
|
396
396
|
- spec/record/endpoints_spec.rb
|
397
397
|
- spec/record/equality_spec.rb
|
398
398
|
- spec/record/error_handling_integration_spec.rb
|
@@ -472,7 +472,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
472
472
|
version: '0'
|
473
473
|
requirements:
|
474
474
|
- Ruby >= 2.3.0
|
475
|
-
|
475
|
+
rubyforge_project:
|
476
|
+
rubygems_version: 2.7.8
|
476
477
|
signing_key:
|
477
478
|
specification_version: 4
|
478
479
|
summary: 'REST services accelerator: Rails gem providing an easy, active-record-like
|
@@ -591,8 +592,8 @@ test_files:
|
|
591
592
|
- spec/record/dig_configuration_spec.rb
|
592
593
|
- spec/record/dup_spec.rb
|
593
594
|
- spec/record/endpoint_inheritance_spec.rb
|
594
|
-
- spec/record/endpoint_misconfiguration_spec.rb
|
595
595
|
- spec/record/endpoint_options_spec.rb
|
596
|
+
- spec/record/endpoint_priorities_spec.rb
|
596
597
|
- spec/record/endpoints_spec.rb
|
597
598
|
- spec/record/equality_spec.rb
|
598
599
|
- spec/record/error_handling_integration_spec.rb
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rails_helper'
|
4
|
-
|
5
|
-
describe LHS::Record do
|
6
|
-
context 'misconfiguration of endpoints' do
|
7
|
-
it 'fails trying to add ambiguous endpoints' do
|
8
|
-
expect(
|
9
|
-
lambda {
|
10
|
-
class Record < LHS::Record
|
11
|
-
endpoint '{+datastore}/v2/feedbacks'
|
12
|
-
endpoint '{+datastore}/v2/reviews'
|
13
|
-
end
|
14
|
-
}
|
15
|
-
).to raise_error(/Ambiguous endpoints/)
|
16
|
-
|
17
|
-
expect(
|
18
|
-
lambda {
|
19
|
-
class Record < LHS::Record
|
20
|
-
endpoint '{+datastore}/v2/{campaign_id}/feedbacks'
|
21
|
-
endpoint '{+datastore}/v2/{campaign_id}/reviews'
|
22
|
-
end
|
23
|
-
}
|
24
|
-
).to raise_error(/Ambiguous endpoints/)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|