lhs 5.6.4 → 5.6.5
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/lhs/concerns/record/request.rb +36 -11
- data/lib/lhs/version.rb +1 -1
- data/spec/record/includes_spec.rb +24 -0
- 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: c65a63aa10738241bdb3ba6c085025cee24281c2
|
4
|
+
data.tar.gz: 5e2dbd3c4d0c7860059728ea694a399b6d53eec4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37868d94b6f13f08fa2ef796b210e682e4f9162275b1a6770fa37b73984fd1718092dc7c799c81190d8cd74edb4885284ac043ebe33fdf2807cbaa4c91c59b7f
|
7
|
+
data.tar.gz: fb80f7203c93908654728ba73df28ba159509904d3c665546f6874f73079b6fc6be6d53c909d390b9ae062c87fe52ca9bb8c76401139cd58bfe5963365be2572
|
@@ -38,23 +38,48 @@ class LHS::Record
|
|
38
38
|
end
|
39
39
|
|
40
40
|
# Extends existing raw data with additionaly fetched data
|
41
|
-
def extend_raw_data(data, addition, key)
|
41
|
+
def extend_raw_data!(data, addition, key)
|
42
42
|
return if addition.empty?
|
43
43
|
if data.collection?
|
44
|
-
data
|
45
|
-
item = item[i] if item.is_a? LHS::Collection
|
46
|
-
link = item[key.to_sym]
|
47
|
-
link.merge_raw!(addition[i]) if link.present?
|
48
|
-
end
|
44
|
+
extend_base_collection!(data, addition, key)
|
49
45
|
elsif data[key]._raw.is_a? Array
|
50
|
-
data
|
51
|
-
|
52
|
-
|
53
|
-
|
46
|
+
extend_base_array!(data, addition, key)
|
47
|
+
elsif data.item?
|
48
|
+
extend_base_item!(data, addition, key)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def extend_base_collection!(data, addition, key)
|
53
|
+
data.each_with_index do |item, i|
|
54
|
+
item = item[i] if item.is_a? LHS::Collection
|
55
|
+
link = item[key.to_sym]
|
56
|
+
link.merge_raw!(addition[i]) if link.present?
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def extend_base_array!(data, addition, key)
|
61
|
+
data[key].zip(addition) do |item, additional_item|
|
62
|
+
item._raw.merge!(additional_item._raw)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def extend_base_item!(data, addition, key)
|
67
|
+
if addition.collection?
|
68
|
+
extend_base_item_with_collection!(data, addition, key)
|
69
|
+
else # simple case merges hash into hash
|
54
70
|
data._raw[key.to_sym].merge!(addition._raw)
|
55
71
|
end
|
56
72
|
end
|
57
73
|
|
74
|
+
def extend_base_item_with_collection!(data, addition, key)
|
75
|
+
target = data[key]
|
76
|
+
if target._raw.is_a? Array
|
77
|
+
data[key] = addition.map(&:_raw)
|
78
|
+
else # hash with items
|
79
|
+
target._raw[items_key] = addition.map(&:_raw)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
58
83
|
def handle_includes(includes, data)
|
59
84
|
if includes.is_a? Hash
|
60
85
|
includes.each { |included, sub_includes| handle_include(included, data, sub_includes) }
|
@@ -76,7 +101,7 @@ class LHS::Record
|
|
76
101
|
url_option_for(data, included)
|
77
102
|
end
|
78
103
|
addition = load_include(options, data, sub_includes)
|
79
|
-
extend_raw_data(data, addition, included)
|
104
|
+
extend_raw_data!(data, addition, included)
|
80
105
|
end
|
81
106
|
|
82
107
|
def skip_loading_includes?(data, included)
|
data/lib/lhs/version.rb
CHANGED
@@ -312,4 +312,28 @@ describe LHS::Record do
|
|
312
312
|
expect(place.available_products.empty?).to eq true
|
313
313
|
end
|
314
314
|
end
|
315
|
+
|
316
|
+
context 'extend items with arrays' do
|
317
|
+
it 'extends base items with arrays' do
|
318
|
+
class Place < LHS::Record
|
319
|
+
endpoint ':datastore/place'
|
320
|
+
endpoint ':datastore/place/:id'
|
321
|
+
end
|
322
|
+
|
323
|
+
stub_request(:get, "#{datastore}/place/1")
|
324
|
+
.to_return(body: {
|
325
|
+
'contracts' => {
|
326
|
+
'items' => [{ 'href' => "#{datastore}/place/1/contacts/1" }]
|
327
|
+
}
|
328
|
+
}.to_json)
|
329
|
+
|
330
|
+
stub_request(:get, "#{datastore}/place/1/contacts/1")
|
331
|
+
.to_return(body: {
|
332
|
+
'products' => { 'href' => "#{datastore}/place/1/contacts/1/products" }
|
333
|
+
}.to_json)
|
334
|
+
|
335
|
+
place = Place.includes(:contracts).find(1)
|
336
|
+
expect(place.contracts.first.products.href).to eq "#{datastore}/place/1/contacts/1/products"
|
337
|
+
end
|
338
|
+
end
|
315
339
|
end
|