lhs 9.0.1 → 9.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/lhs/concerns/record/request.rb +15 -5
- data/lib/lhs/version.rb +1 -1
- data/spec/record/includes_all_spec.rb +21 -0
- data/spec/record/includes_spec.rb +26 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0073ba2cc1f6367f97cd507e4437aebb252f5f5b
|
4
|
+
data.tar.gz: 52687195c84cf5a5f5f122d41d8fb52389ff3b54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29226d8c8a1504a986321f5a25e0ff84358b50545404d5dfbb423af85dce4abeaeb9eaf0e68b19e64c1ce11e0b69df8b70e7fb45389bc051a9632520c5043747
|
7
|
+
data.tar.gz: 86a699cc56dad77686ed4e2b0428fd4ee56acb074d6dddde697001a61737b293242fdadb317f39662cd7b2e98d63e0ee59a92ebf825e7b770494a9fe34bce40f
|
data/README.md
CHANGED
@@ -27,6 +27,8 @@ Please store all defined LHS::Records in `app/models` as they are not autoloaded
|
|
27
27
|
|
28
28
|
You setup a LHS::Record by configuring one or multiple endpoints. You can also add request options for an endpoint (see following example).
|
29
29
|
|
30
|
+
The following example uses the `LHC::Caching` interceptor from [lhc-core-interceptors](https://github.com/local-ch/lhc-core-interceptors#cache-interceptor).
|
31
|
+
|
30
32
|
```ruby
|
31
33
|
class Record < LHS::Record
|
32
34
|
|
@@ -61,7 +61,12 @@ class LHS::Record
|
|
61
61
|
data.each_with_index do |item, i|
|
62
62
|
item = item[i] if item.is_a? LHS::Collection
|
63
63
|
link = item[key.to_sym]
|
64
|
-
|
64
|
+
next if link.blank?
|
65
|
+
link.merge_raw!(addition[i]) && next if !link.collection?
|
66
|
+
|
67
|
+
link.each_with_index do |item, j|
|
68
|
+
item.merge_raw!(addition[i + j]) if item.present?
|
69
|
+
end
|
65
70
|
end
|
66
71
|
end
|
67
72
|
|
@@ -175,7 +180,7 @@ class LHS::Record
|
|
175
180
|
def load_and_merge_remaining_objects!(data, options)
|
176
181
|
if paginated?(data._raw)
|
177
182
|
load_and_merge_paginated_collection!(data, options)
|
178
|
-
elsif data.collection? && paginated?(data.first._raw)
|
183
|
+
elsif data.collection? && paginated?(data.first.try(:_raw))
|
179
184
|
load_and_merge_set_of_paginated_collections!(data, options)
|
180
185
|
end
|
181
186
|
end
|
@@ -320,13 +325,13 @@ class LHS::Record
|
|
320
325
|
def options_for_multiple(data, key = nil)
|
321
326
|
data.map do |item|
|
322
327
|
url_option_for(item, key)
|
323
|
-
end
|
328
|
+
end.flatten
|
324
329
|
end
|
325
330
|
|
326
331
|
def options_for_nested_items(data, key = nil)
|
327
332
|
data[key].map do |item|
|
328
333
|
url_option_for(item)
|
329
|
-
end
|
334
|
+
end.flatten
|
330
335
|
end
|
331
336
|
|
332
337
|
def options_for_next_batch(record, pagination, options, parent_data = nil)
|
@@ -406,7 +411,12 @@ class LHS::Record
|
|
406
411
|
|
407
412
|
def url_option_for(item, key = nil)
|
408
413
|
link = key ? item[key] : item
|
409
|
-
return
|
414
|
+
return if link.blank?
|
415
|
+
return { url: link.href } if !link.collection?
|
416
|
+
|
417
|
+
link.map do |item|
|
418
|
+
{ url: item.href } if item.present? && item.href.present?
|
419
|
+
end.compact
|
410
420
|
end
|
411
421
|
end
|
412
422
|
end
|
data/lib/lhs/version.rb
CHANGED
@@ -115,5 +115,26 @@ describe LHS::Record do
|
|
115
115
|
expect(products_request_page_2).to have_been_requested.at_least_once
|
116
116
|
expect(products_request_page_3).to have_been_requested.at_least_once
|
117
117
|
end
|
118
|
+
|
119
|
+
context 'includes for an empty array' do
|
120
|
+
before(:each) do
|
121
|
+
class Contract < LHS::Record
|
122
|
+
endpoint 'http://datastore/contracts/:id'
|
123
|
+
end
|
124
|
+
stub_request(:get, "http://datastore/contracts/1")
|
125
|
+
.to_return(body: {
|
126
|
+
options: []
|
127
|
+
}.to_json)
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'includes_all in case of an empty array' do
|
131
|
+
expect(lambda do
|
132
|
+
Contract
|
133
|
+
.includes(:product)
|
134
|
+
.includes_all(:options)
|
135
|
+
.find(1)
|
136
|
+
end).not_to raise_error
|
137
|
+
end
|
138
|
+
end
|
118
139
|
end
|
119
140
|
end
|
@@ -469,4 +469,30 @@ describe LHS::Record do
|
|
469
469
|
expect(place.contracts.to_a).to eq([])
|
470
470
|
end
|
471
471
|
end
|
472
|
+
|
473
|
+
context 'include and merge arrays when calling find in parallel' do
|
474
|
+
before(:each) do
|
475
|
+
class Place < LHS::Record
|
476
|
+
endpoint 'http://datastore/places/:id'
|
477
|
+
end
|
478
|
+
stub_request(:get, 'http://datastore/places/1')
|
479
|
+
.to_return(body: {
|
480
|
+
category_relations: [{ href: 'http://datastore/category/1' }, { href: 'http://datastore/category/2' }]
|
481
|
+
}.to_json)
|
482
|
+
stub_request(:get, 'http://datastore/places/2')
|
483
|
+
.to_return(body: {
|
484
|
+
category_relations: [{ href: 'http://datastore/category/2' }, { href: 'http://datastore/category/1' }]
|
485
|
+
}.to_json)
|
486
|
+
stub_request(:get, "http://datastore/category/1").to_return(body: { name: 'Food' }.to_json)
|
487
|
+
stub_request(:get, "http://datastore/category/2").to_return(body: { name: 'Drinks' }.to_json)
|
488
|
+
end
|
489
|
+
|
490
|
+
it 'includes and merges linked resources in case of an array of links' do
|
491
|
+
places = Place
|
492
|
+
.includes(:category_relations)
|
493
|
+
.find(1, 2)
|
494
|
+
expect(places[0].category_relations[0].name).to eq 'Food'
|
495
|
+
expect(places[1].category_relations[0].name).to eq 'Drinks'
|
496
|
+
end
|
497
|
+
end
|
472
498
|
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: 9.0.
|
4
|
+
version: 9.0.2
|
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: 2017-02-
|
11
|
+
date: 2017-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lhc
|