lhs 5.4.2 → 5.5.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 +34 -2
- data/lib/lhs/concerns/record/request.rb +14 -2
- data/lib/lhs/version.rb +1 -1
- data/spec/record/includes_spec.rb +26 -0
- metadata +2 -4
- data/docs/examples/claim_no_include.json +0 -16
- data/docs/examples/claim_with_include.json +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f470a5aba78054aa70cc3479afb69bc0dd92814
|
4
|
+
data.tar.gz: b1b7436c1998cb1280d6a3c2f11f59e9a99e91d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8385de082cb82e468583343d4d5ad78db3f7ac6d4265c7d8faeb399ad26cfa4a4d61cde15243ca9782fca0079f79d73c6952a675cc3cc9d94feced5de2cde1b9
|
7
|
+
data.tar.gz: 04b937fe66115b2fa3020993fb40b230a01fdb2f60a98ade93ef6715881a0133e7a3b136a6b902083a4ebc8d94ebd3299d0b6e7cf80782266a771746bb37d990
|
data/README.md
CHANGED
@@ -302,8 +302,40 @@ The implementation is heavily influenced by [http://guides.rubyonrails.org/activ
|
|
302
302
|
claims = Claims.includes(:localch_account).where(place_id: 'huU90mB_6vAfUdVz_uDoyA')
|
303
303
|
claims.first.localch_account.email # 'test@email.com'
|
304
304
|
```
|
305
|
-
|
306
|
-
|
305
|
+
|
306
|
+
Before include:
|
307
|
+
```json
|
308
|
+
{
|
309
|
+
"href" : "http://datastore/v2/places/huU90mB_6vAfUdVz_uDoyA/claims",
|
310
|
+
"items" : [
|
311
|
+
{
|
312
|
+
"href" : "http://datastore/v2/localch-accounts/6bSss0y93lK0MrVsgdNNdg/claims/huU90mB_6vAfUdVz_uDoyA",
|
313
|
+
"localch_account" : {
|
314
|
+
"href" : "http://datastore/v2/localch-accounts/6bSss0y93lK0MrVsgdNNdg"
|
315
|
+
}
|
316
|
+
}
|
317
|
+
]
|
318
|
+
}
|
319
|
+
```
|
320
|
+
|
321
|
+
After include:
|
322
|
+
```json
|
323
|
+
{
|
324
|
+
"href" : "http://datastore/v2/places/huU90mB_6vAfUdVz_uDoyA/claims",
|
325
|
+
"items" : [
|
326
|
+
{
|
327
|
+
"href" : "http://datastore/v2/localch-accounts/6bSss0y93lK0MrVsgdNNdg/claims/huU90mB_6vAfUdVz_uDoyA",
|
328
|
+
"localch_account" : {
|
329
|
+
"href" : "http://datastore/v2/localch-accounts/6bSss0y93lK0MrVsgdNNdg",
|
330
|
+
"id" : "6bSss0y93lK0MrVsgdNNdg",
|
331
|
+
"name" : "Myriam",
|
332
|
+
"phone" : "12345678",
|
333
|
+
"email" : "email@gmail.com"
|
334
|
+
}
|
335
|
+
}
|
336
|
+
]
|
337
|
+
}
|
338
|
+
```
|
307
339
|
|
308
340
|
### Two-Level `includes`
|
309
341
|
|
@@ -46,6 +46,10 @@ class LHS::Record
|
|
46
46
|
link = item[key.to_sym]
|
47
47
|
link.merge_raw!(addition[i]) if link.present?
|
48
48
|
end
|
49
|
+
elsif data[key]._raw.is_a? Array
|
50
|
+
data[key].zip(addition) do |item, additional_item|
|
51
|
+
item._raw.merge!(additional_item._raw)
|
52
|
+
end
|
49
53
|
elsif data._proxy.is_a? LHS::Item
|
50
54
|
data._raw[key.to_sym].merge!(addition._raw)
|
51
55
|
end
|
@@ -66,6 +70,8 @@ class LHS::Record
|
|
66
70
|
options =
|
67
71
|
if data.collection?
|
68
72
|
options_for_multiple(data, included)
|
73
|
+
elsif data[included]._raw.is_a?(Array)
|
74
|
+
options_for_nested_items(data, included)
|
69
75
|
else
|
70
76
|
url_option_for(data, included)
|
71
77
|
end
|
@@ -132,6 +138,12 @@ class LHS::Record
|
|
132
138
|
end
|
133
139
|
end
|
134
140
|
|
141
|
+
def options_for_nested_items(data, key)
|
142
|
+
data[key].map do |item|
|
143
|
+
url_option_for(item)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
135
147
|
# Merge explicit params and take configured endpoints options as base
|
136
148
|
def process_options(options, endpoint)
|
137
149
|
options[:params].deep_symbolize_keys! if options[:params]
|
@@ -167,8 +179,8 @@ class LHS::Record
|
|
167
179
|
data
|
168
180
|
end
|
169
181
|
|
170
|
-
def url_option_for(item, key)
|
171
|
-
link = item[key]
|
182
|
+
def url_option_for(item, key = nil)
|
183
|
+
link = key ? item[key] : item
|
172
184
|
return { url: link.href } if link.present? && link.href.present?
|
173
185
|
end
|
174
186
|
end
|
data/lib/lhs/version.rb
CHANGED
@@ -266,4 +266,30 @@ describe LHS::Record do
|
|
266
266
|
Services::Feedback.includes(campaign: :entry).find(123)
|
267
267
|
end
|
268
268
|
end
|
269
|
+
|
270
|
+
context 'arrays' do
|
271
|
+
it 'includes items of arrays' do
|
272
|
+
class Place < LHS::Record
|
273
|
+
endpoint ':datastore/place'
|
274
|
+
endpoint ':datastore/place/:id'
|
275
|
+
end
|
276
|
+
|
277
|
+
stub_request(:get, "#{datastore}/place/1")
|
278
|
+
.to_return(body: {
|
279
|
+
'relations' => [
|
280
|
+
{ 'href' => "#{datastore}/place/relations/2" },
|
281
|
+
{ 'href' => "#{datastore}/place/relations/3" }
|
282
|
+
]
|
283
|
+
}.to_json)
|
284
|
+
|
285
|
+
stub_request(:get, "#{datastore}/place/relations/2")
|
286
|
+
.to_return(body: { name: 'Category' }.to_json)
|
287
|
+
stub_request(:get, "#{datastore}/place/relations/3")
|
288
|
+
.to_return(body: { name: 'ZeFrank' }.to_json)
|
289
|
+
|
290
|
+
place = Place.includes(:relations).find(1)
|
291
|
+
expect(place.relations.first.name).to eq 'Category'
|
292
|
+
expect(place.relations[1].name).to eq 'ZeFrank'
|
293
|
+
end
|
294
|
+
end
|
269
295
|
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: 5.
|
4
|
+
version: 5.5.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: 2016-05-
|
11
|
+
date: 2016-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lhc
|
@@ -173,8 +173,6 @@ files:
|
|
173
173
|
- cider-ci/scripts/rubocop.yml
|
174
174
|
- cider-ci/scripts/ruby-version.yml
|
175
175
|
- cider-ci/scripts/tmp-cache.yml
|
176
|
-
- docs/examples/claim_no_include.json
|
177
|
-
- docs/examples/claim_with_include.json
|
178
176
|
- lhs.gemspec
|
179
177
|
- lib/lhs.rb
|
180
178
|
- lib/lhs/collection.rb
|
@@ -1,16 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"href" : "http://silo2:8082/v2/places/huU90mB_6vAfUdVz_uDoyA/claims",
|
3
|
-
"items" : [
|
4
|
-
{
|
5
|
-
"href" : "http://silo2:8082/v2/localch-accounts/6bSss0y93lK0MrVsgdNNdg/claims/huU90mB_6vAfUdVz_uDoyA",
|
6
|
-
"localch_account" : {
|
7
|
-
"href" : "http://silo2:8082/v2/localch-accounts/6bSss0y93lK0MrVsgdNNdg"
|
8
|
-
},
|
9
|
-
"place" : {
|
10
|
-
"href" : "http://silo2:8082/v2/places/huU90mB_6vAfUdVz_uDoyA"
|
11
|
-
},
|
12
|
-
"created_date" : "2014-05-06T14:15:59.115+02:00",
|
13
|
-
"method" : "MBA"
|
14
|
-
}
|
15
|
-
]
|
16
|
-
}
|
@@ -1,47 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"href" : "http://silo2:8082/v2/places/huU90mB_6vAfUdVz_uDoyA/claims",
|
3
|
-
"items" : [
|
4
|
-
{
|
5
|
-
"href" : "http://silo2:8082/v2/localch-accounts/6bSss0y93lK0MrVsgdNNdg/claims/huU90mB_6vAfUdVz_uDoyA",
|
6
|
-
"localch_account" : {
|
7
|
-
"href" : "http://silo2:8082/v2/localch-accounts/6bSss0y93lK0MrVsgdNNdg",
|
8
|
-
"id" : "6bSss0y93lK0MrVsgdNNdg",
|
9
|
-
"name" : "Myriam",
|
10
|
-
"phone" : "0791994817",
|
11
|
-
"email" : "myriam.salm@gmail.com",
|
12
|
-
"language" : "en",
|
13
|
-
"created_date" : "2014-05-06T14:15:58.809+02:00",
|
14
|
-
"claims" : {
|
15
|
-
"href" : "http://silo2:8082/v2/localch-accounts/6bSss0y93lK0MrVsgdNNdg/claims",
|
16
|
-
"items" : [
|
17
|
-
{
|
18
|
-
"href" : "http://silo2:8082/v2/localch-accounts/6bSss0y93lK0MrVsgdNNdg/claims/huU90mB_6vAfUdVz_uDoyA",
|
19
|
-
"localch_account" : {
|
20
|
-
"href" : "http://silo2:8082/v2/localch-accounts/6bSss0y93lK0MrVsgdNNdg"
|
21
|
-
},
|
22
|
-
"place" : {
|
23
|
-
"href" : "http://silo2:8082/v2/places/huU90mB_6vAfUdVz_uDoyA"
|
24
|
-
},
|
25
|
-
"created_date" : "2014-05-06T14:15:59.115+02:00",
|
26
|
-
"method" : "MBA"
|
27
|
-
}
|
28
|
-
],
|
29
|
-
"total" : 1
|
30
|
-
},
|
31
|
-
"password_hash" : "$2a$10$LFb8IhUSK/0GBZoXRQE/2euRkIdQpTqI8Cw4OFkStPf5XvItvlhJK",
|
32
|
-
"accepted_agbs" : {
|
33
|
-
"href" : "http://silo2:8082/v2/localch-accounts/6bSss0y93lK0MrVsgdNNdg/accepted-agbs",
|
34
|
-
"items" : [],
|
35
|
-
"total" : 0
|
36
|
-
},
|
37
|
-
"enabled" : true,
|
38
|
-
"non_locked" : true
|
39
|
-
},
|
40
|
-
"place" : {
|
41
|
-
"href" : "http://silo2:8082/v2/places/huU90mB_6vAfUdVz_uDoyA"
|
42
|
-
},
|
43
|
-
"created_date" : "2014-05-06T14:15:59.115+02:00",
|
44
|
-
"method" : "MBA"
|
45
|
-
}
|
46
|
-
]
|
47
|
-
}
|