lhs 15.2.4 → 15.2.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 +18 -2
- data/lib/lhs/version.rb +1 -1
- data/spec/record/includes_spec.rb +44 -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: 74a7df6c84bd30e35e9a0d4fe14bd0d4023c71e0
|
|
4
|
+
data.tar.gz: 899c8e3029fbee1bc9f42b68022eb0fd38d4fc5a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2dba61e4adcd12cd589c585bdf3d4fc96647b015c331d3b8ff55a681089019fe3f19f4f68860fb2b4a224332a3af447b701c1f05de7b59ead1f4459cc8cc60a5
|
|
7
|
+
data.tar.gz: 94e90e2cb651d2518b138cf76691f6dbc8c544ab14e619cb23c1dd1fc67e29680d3b93ac16e8471ce019ff4457de5fd1e4d60b2fa29fd2fa0fe392bec20f1bee
|
|
@@ -105,10 +105,19 @@ class LHS::Record
|
|
|
105
105
|
.each_with_index do |item, index|
|
|
106
106
|
item_addition = addition[index]
|
|
107
107
|
next if item_addition.nil? || item.nil?
|
|
108
|
-
|
|
108
|
+
if item_addition._raw.is_a?(Array)
|
|
109
|
+
extend_base_collection_with_array!(item, item_addition._raw)
|
|
110
|
+
else
|
|
111
|
+
item.merge! item_addition._raw
|
|
112
|
+
end
|
|
109
113
|
end
|
|
110
114
|
end
|
|
111
115
|
|
|
116
|
+
def extend_base_collection_with_array!(item, addition)
|
|
117
|
+
item[items_key] ||= []
|
|
118
|
+
item[items_key].concat(addition)
|
|
119
|
+
end
|
|
120
|
+
|
|
112
121
|
def extend_base_array!(data, addition, key)
|
|
113
122
|
data[key].zip(addition) do |item, additional_item|
|
|
114
123
|
item._raw.merge!(additional_item._raw) if additional_item.present?
|
|
@@ -190,7 +199,14 @@ class LHS::Record
|
|
|
190
199
|
if addition.item?
|
|
191
200
|
(addition._raw.keys - [:href]).empty?
|
|
192
201
|
elsif addition.collection?
|
|
193
|
-
addition.all?
|
|
202
|
+
addition.all? do |item|
|
|
203
|
+
next if item.blank?
|
|
204
|
+
if item._raw.is_a?(Hash)
|
|
205
|
+
(item._raw.keys - [:href]).empty?
|
|
206
|
+
elsif item._raw.is_a?(Array)
|
|
207
|
+
item.any? { |item| (item._raw.keys - [:href]).empty? }
|
|
208
|
+
end
|
|
209
|
+
end
|
|
194
210
|
end
|
|
195
211
|
end
|
|
196
212
|
|
data/lib/lhs/version.rb
CHANGED
|
@@ -560,4 +560,48 @@ describe LHS::Record do
|
|
|
560
560
|
expect(places[1].category_relations[0].name).to eq 'Drinks'
|
|
561
561
|
end
|
|
562
562
|
end
|
|
563
|
+
|
|
564
|
+
context 'single href with array response' do
|
|
565
|
+
it 'extends base items with arrays' do
|
|
566
|
+
class Sector < LHS::Record
|
|
567
|
+
endpoint '{+datastore}/sectors'
|
|
568
|
+
endpoint '{+datastore}/sectors/{id}'
|
|
569
|
+
end
|
|
570
|
+
|
|
571
|
+
stub_request(:get, "#{datastore}/sectors")
|
|
572
|
+
.with(query: hash_including(key: 'my_service'))
|
|
573
|
+
.to_return(body: [
|
|
574
|
+
{
|
|
575
|
+
href: "#{datastore}/sectors/1",
|
|
576
|
+
services: {
|
|
577
|
+
href: "#{datastore}/sectors/1/services"
|
|
578
|
+
},
|
|
579
|
+
keys: [
|
|
580
|
+
{
|
|
581
|
+
key: 'my_service',
|
|
582
|
+
language: 'de'
|
|
583
|
+
}
|
|
584
|
+
]
|
|
585
|
+
}
|
|
586
|
+
].to_json)
|
|
587
|
+
|
|
588
|
+
stub_request(:get, "#{datastore}/sectors/1/services")
|
|
589
|
+
.to_return(body: [
|
|
590
|
+
{
|
|
591
|
+
href: "#{datastore}/services/s1",
|
|
592
|
+
price_in_cents: 9900,
|
|
593
|
+
key: 'my_service_service_1'
|
|
594
|
+
},
|
|
595
|
+
{
|
|
596
|
+
href: "#{datastore}/services/s2",
|
|
597
|
+
price_in_cents: 19900,
|
|
598
|
+
key: 'my_service_service_2'
|
|
599
|
+
}
|
|
600
|
+
].to_json)
|
|
601
|
+
|
|
602
|
+
sector = Sector.includes(:services).find_by(key: 'my_service')
|
|
603
|
+
expect(sector.services.length).to eq 2
|
|
604
|
+
expect(sector.services.first.key).to eq 'my_service_service_1'
|
|
605
|
+
end
|
|
606
|
+
end
|
|
563
607
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lhs
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 15.2.
|
|
4
|
+
version: 15.2.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- https://github.com/local-ch/lhs/graphs/contributors
|
|
@@ -437,7 +437,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
437
437
|
requirements:
|
|
438
438
|
- Ruby >= 2.3.0
|
|
439
439
|
rubyforge_project:
|
|
440
|
-
rubygems_version: 2.6.
|
|
440
|
+
rubygems_version: 2.6.12
|
|
441
441
|
signing_key:
|
|
442
442
|
specification_version: 4
|
|
443
443
|
summary: Rails gem providing an easy, active-record-like interface for http json services
|