lhs 22.1.1.pre → 23.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -2
- data/lhs.gemspec +1 -1
- data/lib/lhs/concerns/record/request.rb +7 -5
- data/lib/lhs/version.rb +1 -1
- data/spec/record/includes_first_page_spec.rb +14 -4
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 562b089ef00109a1306d02abae66e41f5c8145f8543a9b9f9dffb75fe2133d7b
|
4
|
+
data.tar.gz: c04bd6e68e91cc8b31348cc6745970775719ab7f7a00ee7c9bdbbf71f96deb79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e3e2fad39c0d7dd4057823a8b1645a42636dfbe020bfbb7405beff04ef578084ba13f44246556820a9ce77b4674ef8ecac2de05159e5820741273b57c1e43b1
|
7
|
+
data.tar.gz: 18e8f76ad0d212f5153c0ff4eb13c730ae9c4e3d089708fced3d8c409361ababe528d601e6761733c4a50925825e10b1fb36352ec527ea255683e55cacfd5fa6
|
data/README.md
CHANGED
@@ -99,6 +99,8 @@ record.review # "Lunch was great
|
|
99
99
|
* [Change/Update existing records](#changeupdate-existing-records)
|
100
100
|
* [save](#save)
|
101
101
|
* [update](#update)
|
102
|
+
* [Directly via Record](#directly-via-record)
|
103
|
+
* [per Instance](#per-instance)
|
102
104
|
* [partial_update](#partial_update)
|
103
105
|
* [Endpoint url parameter injection during record creation/change](#endpoint-url-parameter-injection-during-record-creationchange)
|
104
106
|
* [Record validation](#record-validation)
|
@@ -119,8 +121,8 @@ record.review # "Lunch was great
|
|
119
121
|
* [Record getters](#record-getters)
|
120
122
|
* [Include linked resources (hyperlinks and hypermedia)](#include-linked-resources-hyperlinks-and-hypermedia)
|
121
123
|
* [Generate links from parameters](#generate-links-from-parameters)
|
122
|
-
* [Ensure the whole linked collection is included
|
123
|
-
* [Include the first linked page
|
124
|
+
* [Ensure the whole linked collection is included with includes](#ensure-the-whole-linked-collection-is-included-with-includes)
|
125
|
+
* [Include only the first linked page of a linked collection: includes_first_page](#include-only-the-first-linked-page-of-a-linked-collection-includes_first_page)
|
124
126
|
* [Include various levels of linked data](#include-various-levels-of-linked-data)
|
125
127
|
* [Identify and cast known records when including records](#identify-and-cast-known-records-when-including-records)
|
126
128
|
* [Apply options for requests performed to fetch included records](#apply-options-for-requests-performed-to-fetch-included-records)
|
@@ -152,6 +154,7 @@ record.review # "Lunch was great
|
|
152
154
|
|
153
155
|
|
154
156
|
|
157
|
+
|
155
158
|
## Installation/Startup checklist
|
156
159
|
|
157
160
|
- [ ] Install LHS gem, preferably via `Gemfile`
|
@@ -2276,6 +2279,17 @@ In parallel:
|
|
2276
2279
|
GET https://service.example.com/places/4 { headers: { 'Authentication': 'Bearer 123' } }
|
2277
2280
|
```
|
2278
2281
|
|
2282
|
+
Here is another example, if you want to ignore errors, that occure while you fetch included resources:
|
2283
|
+
|
2284
|
+
```ruby
|
2285
|
+
# app/controllers/some_controller.rb
|
2286
|
+
|
2287
|
+
feedback = Feedback
|
2288
|
+
.includes(campaign: :entry)
|
2289
|
+
.references(campaign: { ignored_errors: [LHC::NotFound] })
|
2290
|
+
.find(12345)
|
2291
|
+
```
|
2292
|
+
|
2279
2293
|
### Record batch processing
|
2280
2294
|
|
2281
2295
|
**Be careful using methods for batch processing. They could result in a lot of HTTP requests!**
|
data/lhs.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
|
|
24
24
|
|
25
25
|
s.add_dependency 'activemodel'
|
26
26
|
s.add_dependency 'activesupport', '>= 4.2.11'
|
27
|
-
s.add_dependency 'lhc', '>=
|
27
|
+
s.add_dependency 'lhc', '>= 11.2.0', '< 12'
|
28
28
|
s.add_dependency 'local_uri'
|
29
29
|
|
30
30
|
s.add_development_dependency 'capybara'
|
@@ -138,6 +138,7 @@ class LHS::Record
|
|
138
138
|
end
|
139
139
|
|
140
140
|
def extend_base_item!(data, addition, key)
|
141
|
+
return if addition.nil?
|
141
142
|
if addition.collection?
|
142
143
|
extend_base_item_with_collection!(data, addition, key)
|
143
144
|
else # simple case merges hash into hash
|
@@ -205,7 +206,7 @@ class LHS::Record
|
|
205
206
|
def expand_addition!(data, included, reference)
|
206
207
|
addition = data[included]
|
207
208
|
options = options_for_data(addition)
|
208
|
-
options = extend_with_reference(options, reference
|
209
|
+
options = extend_with_reference(options, reference)
|
209
210
|
record = record_for_options(options) || self
|
210
211
|
options = convert_options_to_endpoints(options) if record_for_options(options)
|
211
212
|
expanded_data = record.request(options)
|
@@ -217,7 +218,7 @@ class LHS::Record
|
|
217
218
|
if addition.item?
|
218
219
|
(addition._raw.keys - [:href]).any?
|
219
220
|
elsif addition.collection?
|
220
|
-
addition.
|
221
|
+
addition.any? do |item|
|
221
222
|
next if item.blank?
|
222
223
|
if item._raw.is_a?(Hash)
|
223
224
|
(item._raw.keys - [:href]).any?
|
@@ -230,7 +231,8 @@ class LHS::Record
|
|
230
231
|
|
231
232
|
# Extends request options with options provided for this reference
|
232
233
|
def extend_with_reference(options, reference)
|
233
|
-
return options
|
234
|
+
return options if reference.blank?
|
235
|
+
reference = reference.except(:url)
|
234
236
|
options ||= {}
|
235
237
|
if options.is_a?(Array)
|
236
238
|
options.map { |request_options| request_options.merge(reference) if request_options.present? }
|
@@ -344,7 +346,7 @@ class LHS::Record
|
|
344
346
|
end
|
345
347
|
|
346
348
|
# Load additional resources that are requested with include
|
347
|
-
def load_include(options,
|
349
|
+
def load_include(options, _data, sub_includes, references)
|
348
350
|
record = record_for_options(options) || self
|
349
351
|
options = convert_options_to_endpoints(options) if record_for_options(options)
|
350
352
|
prepare_options_for_include_request!(options, sub_includes, references)
|
@@ -364,7 +366,7 @@ class LHS::Record
|
|
364
366
|
|
365
367
|
def load_include_simple!(options, record)
|
366
368
|
data = record.request(options)
|
367
|
-
warn "[WARNING] You included `#{options[:url]}`, but this endpoint is paginated. You might want to use `includes_all` instead of `includes` (https://github.com/local-ch/lhs#includes_all-for-paginated-endpoints)." if paginated?(data._raw)
|
369
|
+
warn "[WARNING] You included `#{options[:url]}`, but this endpoint is paginated. You might want to use `includes_all` instead of `includes` (https://github.com/local-ch/lhs#includes_all-for-paginated-endpoints)." if data && paginated?(data._raw)
|
368
370
|
data
|
369
371
|
end
|
370
372
|
|
data/lib/lhs/version.rb
CHANGED
@@ -224,7 +224,7 @@ describe LHS::Record do
|
|
224
224
|
end
|
225
225
|
|
226
226
|
context 'links pointing to nowhere' do
|
227
|
-
|
227
|
+
before do
|
228
228
|
class Feedback < LHS::Record
|
229
229
|
endpoint '{+datastore}/feedbacks'
|
230
230
|
endpoint '{+datastore}/feedbacks/{id}'
|
@@ -238,10 +238,20 @@ describe LHS::Record do
|
|
238
238
|
|
239
239
|
stub_request(:get, "#{datastore}/content-ads/51dfc5690cf271c375c5a12d")
|
240
240
|
.to_return(status: 404)
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'raises LHC::NotFound for links that cannot be included' do
|
244
|
+
expect(-> {
|
245
|
+
Feedback.includes_first_page(campaign: :entry).find(123)
|
246
|
+
}).to raise_error LHC::NotFound
|
247
|
+
end
|
241
248
|
|
242
|
-
|
243
|
-
|
244
|
-
|
249
|
+
it 'ignores LHC::NotFound for links that cannot be included if configured so with reference options' do
|
250
|
+
feedback = Feedback
|
251
|
+
.includes_first_page(campaign: :entry)
|
252
|
+
.references(campaign: { ignored_errors: [LHC::NotFound] })
|
253
|
+
.find(123)
|
254
|
+
expect(feedback.campaign._raw.keys.length).to eq 1
|
245
255
|
end
|
246
256
|
end
|
247
257
|
|
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:
|
4
|
+
version: 23.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- https://github.com/local-ch/lhs/graphs/contributors
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 11.2.0
|
48
48
|
- - "<"
|
49
49
|
- !ruby/object:Gem::Version
|
50
50
|
version: '12'
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
requirements:
|
55
55
|
- - ">="
|
56
56
|
- !ruby/object:Gem::Version
|
57
|
-
version:
|
57
|
+
version: 11.2.0
|
58
58
|
- - "<"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '12'
|
@@ -561,9 +561,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
561
561
|
version: 2.3.0
|
562
562
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
563
563
|
requirements:
|
564
|
-
- - "
|
564
|
+
- - ">="
|
565
565
|
- !ruby/object:Gem::Version
|
566
|
-
version:
|
566
|
+
version: '0'
|
567
567
|
requirements:
|
568
568
|
- Ruby >= 2.3.0
|
569
569
|
rubygems_version: 3.0.6
|