lhs 24.1.1 → 25.0.3
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 +10 -0
- data/docs/accessing-data-in-lhs.png +0 -0
- data/lhs.gemspec +1 -1
- data/lib/lhs/collection.rb +1 -1
- data/lib/lhs/concerns/autoload_records.rb +4 -2
- data/lib/lhs/concerns/collection/internal_collection.rb +1 -1
- data/lib/lhs/concerns/record/request.rb +21 -3
- data/lib/lhs/version.rb +1 -1
- data/spec/dummy/app/models/concerns/dummy_customer/some_concern.rb +9 -0
- data/spec/dummy/app/models/dummy_customer.rb +1 -0
- data/spec/record/compact_spec.rb +2 -2
- data/spec/record/includes_expanded_spec.rb +37 -0
- data/spec/record/includes_missing_spec.rb +59 -0
- data/spec/record/references_spec.rb +1 -1
- metadata +15 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7aa5e0e072a78d7029c968c255ac6c41e5425504b7e121fc5c205a672c59d4a7
|
|
4
|
+
data.tar.gz: 59a90ded930e12b7cc54842db415d5d0f2c09ade777eaccc44d9703d4bc1f46a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e953b0d8278c209f1a398298d6bbf85b91469cf285bc7c0470b401cacfce2db7b692822e7d13488c4b36c823cef1c093bc8ffb4a5d2d53ab5782765589711b07
|
|
7
|
+
data.tar.gz: d7124e16eca63583fb58922354253c902bbd86e0079c22e3d8b864a7a80b8acd098128a67c2e32cfe45c6ed28d19158def5a063fec174bdba364435b11054d92
|
data/README.md
CHANGED
|
@@ -126,6 +126,7 @@ record.review # "Lunch was great
|
|
|
126
126
|
* [Include various levels of linked data](#include-various-levels-of-linked-data)
|
|
127
127
|
* [Identify and cast known records when including records](#identify-and-cast-known-records-when-including-records)
|
|
128
128
|
* [Apply options for requests performed to fetch included records](#apply-options-for-requests-performed-to-fetch-included-records)
|
|
129
|
+
* [compact: Remove included resources that didn't return any records](#compact-remove-included-resources-that-didnt-return-any-records)
|
|
129
130
|
* [Record batch processing](#record-batch-processing)
|
|
130
131
|
* [all](#all-1)
|
|
131
132
|
* [Using all, when endpoint does not implement response pagination meta data](#using-all-when-endpoint-does-not-implement-response-pagination-meta-data)
|
|
@@ -149,12 +150,15 @@ record.review # "Lunch was great
|
|
|
149
150
|
* [Test query chains](#test-query-chains)
|
|
150
151
|
* [By explicitly resolving the chain: fetch](#by-explicitly-resolving-the-chain-fetch)
|
|
151
152
|
* [Without resolving the chain: where_values_hash](#without-resolving-the-chain-where_values_hash)
|
|
153
|
+
* [Extended developer documentation](#extended-developer-documentation)
|
|
154
|
+
* [Accessing data in LHS](#accessing-data-in-lhs)
|
|
152
155
|
* [License](#license)
|
|
153
156
|
|
|
154
157
|
|
|
155
158
|
|
|
156
159
|
|
|
157
160
|
|
|
161
|
+
|
|
158
162
|
## Installation/Startup checklist
|
|
159
163
|
|
|
160
164
|
- [ ] Install LHS gem, preferably via `Gemfile`
|
|
@@ -2878,6 +2882,12 @@ expect(
|
|
|
2878
2882
|
).to eq {color: 'red', available: true}
|
|
2879
2883
|
```
|
|
2880
2884
|
|
|
2885
|
+
## Extended developer documentation
|
|
2886
|
+
|
|
2887
|
+
### Accessing data in LHS
|
|
2888
|
+
|
|
2889
|
+

|
|
2890
|
+
|
|
2881
2891
|
## License
|
|
2882
2892
|
|
|
2883
2893
|
[GNU General Public License Version 3.](https://www.gnu.org/licenses/gpl-3.0.en.html)
|
|
Binary file
|
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', '>= 12.1.1', '<
|
|
27
|
+
s.add_dependency 'lhc', '>= 12.1.1', '< 14'
|
|
28
28
|
s.add_dependency 'local_uri'
|
|
29
29
|
|
|
30
30
|
s.add_development_dependency 'capybara'
|
data/lib/lhs/collection.rb
CHANGED
|
@@ -14,7 +14,7 @@ class LHS::Collection < LHS::Proxy
|
|
|
14
14
|
|
|
15
15
|
METHOD_NAMES_EXLCUDED_FROM_WRAPPING = %w(to_a to_ary map).freeze
|
|
16
16
|
|
|
17
|
-
delegate :select, :length, :size, to: :_collection
|
|
17
|
+
delegate :select, :length, :size, :insert, to: :_collection
|
|
18
18
|
delegate :_record, :_raw, to: :_data
|
|
19
19
|
delegate :limit, :count, :total, :offset, :current_page, :start,
|
|
20
20
|
:next?, :previous?, to: :_pagination
|
|
@@ -32,7 +32,7 @@ module AutoloadRecords
|
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
def self.require_direct_inheritance
|
|
35
|
-
model_files.map do |file|
|
|
35
|
+
model_files.sort.map do |file|
|
|
36
36
|
next unless File.read(file).match('LHS::Record')
|
|
37
37
|
require_dependency file
|
|
38
38
|
file.split('models/').last.gsub('.rb', '').classify
|
|
@@ -41,7 +41,9 @@ module AutoloadRecords
|
|
|
41
41
|
|
|
42
42
|
def self.require_inheriting_records(parents)
|
|
43
43
|
model_files.each do |file|
|
|
44
|
-
|
|
44
|
+
file_content = File.read(file)
|
|
45
|
+
next if parents.none? { |parent| file_content.match(/\b#{parent}\b/) }
|
|
46
|
+
next if file_content.match?('extend ActiveSupport::Concern')
|
|
45
47
|
require_dependency file
|
|
46
48
|
end
|
|
47
49
|
end
|
|
@@ -14,7 +14,7 @@ class LHS::Collection < LHS::Proxy
|
|
|
14
14
|
|
|
15
15
|
attr_accessor :raw
|
|
16
16
|
delegate :length, :size, :first, :last, :sample, :[], :present?, :blank?, :empty?,
|
|
17
|
-
:<<, :push, to: :raw
|
|
17
|
+
:<<, :push, :insert, to: :raw
|
|
18
18
|
|
|
19
19
|
def initialize(raw, parent, record)
|
|
20
20
|
self.raw = raw
|
|
@@ -29,7 +29,10 @@ class LHS::Record
|
|
|
29
29
|
if options.is_a?(Hash)
|
|
30
30
|
options.deep_merge(LHS::OptionBlocks::CurrentOptionBlock.options)
|
|
31
31
|
elsif options.is_a?(Array)
|
|
32
|
-
options.map
|
|
32
|
+
options.map do |option|
|
|
33
|
+
return LHS::OptionBlocks::CurrentOptionBlock.options unless option
|
|
34
|
+
option.deep_merge(LHS::OptionBlocks::CurrentOptionBlock.options)
|
|
35
|
+
end
|
|
33
36
|
end
|
|
34
37
|
end
|
|
35
38
|
|
|
@@ -118,9 +121,9 @@ class LHS::Record
|
|
|
118
121
|
else
|
|
119
122
|
options = options_for_data(data, included)
|
|
120
123
|
options = extend_with_reference(options, reference)
|
|
121
|
-
addition =
|
|
124
|
+
addition = load_existing_includes(options, data, sub_includes, reference)
|
|
122
125
|
data.extend!(addition, included)
|
|
123
|
-
expand_addition!(data, included,
|
|
126
|
+
expand_addition!(data, included, reference) unless expanded_data?(addition)
|
|
124
127
|
end
|
|
125
128
|
end
|
|
126
129
|
|
|
@@ -277,6 +280,21 @@ class LHS::Record
|
|
|
277
280
|
end
|
|
278
281
|
end
|
|
279
282
|
|
|
283
|
+
def load_existing_includes(options, data, sub_includes, references)
|
|
284
|
+
if data.collection? && data.any?(&:blank?)
|
|
285
|
+
# filter only existing items
|
|
286
|
+
loaded_includes = load_include(options.compact, data.compact, sub_includes, references)
|
|
287
|
+
# fill up skipped items before returning
|
|
288
|
+
data.each_with_index do |item, index|
|
|
289
|
+
next if item.present?
|
|
290
|
+
loaded_includes.insert(index, {})
|
|
291
|
+
end
|
|
292
|
+
loaded_includes
|
|
293
|
+
else
|
|
294
|
+
load_include(options, data, sub_includes, references)
|
|
295
|
+
end
|
|
296
|
+
end
|
|
297
|
+
|
|
280
298
|
# Load additional resources that are requested with include
|
|
281
299
|
def load_include(options, _data, sub_includes, references)
|
|
282
300
|
record = record_for_options(options) || self
|
data/lib/lhs/version.rb
CHANGED
data/spec/record/compact_spec.rb
CHANGED
|
@@ -38,7 +38,7 @@ describe LHS::Record do
|
|
|
38
38
|
limit: 10
|
|
39
39
|
}.to_json)
|
|
40
40
|
|
|
41
|
-
stub_request(:get, 'http://datastore/users/123/places/789
|
|
41
|
+
stub_request(:get, 'http://datastore/users/123/places/789')
|
|
42
42
|
.to_return(
|
|
43
43
|
body: {
|
|
44
44
|
href: 'http://datastore/users/123/places/789?limit=100',
|
|
@@ -46,7 +46,7 @@ describe LHS::Record do
|
|
|
46
46
|
}.to_json
|
|
47
47
|
)
|
|
48
48
|
|
|
49
|
-
stub_request(:get, 'http://datastore/users/123/places/790
|
|
49
|
+
stub_request(:get, 'http://datastore/users/123/places/790')
|
|
50
50
|
.to_return(
|
|
51
51
|
status: 404,
|
|
52
52
|
body: {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails_helper'
|
|
4
|
+
|
|
5
|
+
describe LHS::Record do
|
|
6
|
+
context 'includes all (expanded)' do
|
|
7
|
+
before do
|
|
8
|
+
class Record < LHS::Record
|
|
9
|
+
endpoint 'http://records/{id}'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
stub_request(:get, "http://records/1")
|
|
13
|
+
.to_return(
|
|
14
|
+
body: {
|
|
15
|
+
car: { href: 'http://records/1/car' }
|
|
16
|
+
}.to_json
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
stub_request(:get, "http://records/1/car?color=blue&limit=100")
|
|
20
|
+
.to_return(
|
|
21
|
+
body: { href: 'http://records/cars/1' }.to_json
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
stub_request(:get, "http://records/cars/1?color=blue&limit=100")
|
|
25
|
+
.to_return(
|
|
26
|
+
body: { name: 'wrum wrum' }.to_json
|
|
27
|
+
)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'expands linked resources and forwards proper reference' do
|
|
31
|
+
record = Record.includes(:car).references(car: { params: { color: :blue } }).find(1)
|
|
32
|
+
expect(
|
|
33
|
+
record.car.name
|
|
34
|
+
).to eq 'wrum wrum'
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails_helper'
|
|
4
|
+
|
|
5
|
+
describe LHS::Record do
|
|
6
|
+
|
|
7
|
+
context 'merge request options ' do
|
|
8
|
+
before do
|
|
9
|
+
class Record < LHS::Record
|
|
10
|
+
endpoint 'http://records/{id}'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
stub_request(:get, 'http://records/1')
|
|
14
|
+
.to_return(body: {
|
|
15
|
+
place_attributes: [
|
|
16
|
+
{ href: 'https://attributes/bar' },
|
|
17
|
+
{ href: 'https://attributes/restaurant' },
|
|
18
|
+
{ href: 'https://attributes/cafe' }
|
|
19
|
+
]
|
|
20
|
+
}.to_json)
|
|
21
|
+
|
|
22
|
+
stub_request(:get, "https://attributes/restaurant?limit=100")
|
|
23
|
+
.to_return(body: {}.to_json)
|
|
24
|
+
stub_request(:get, "https://attributes/restaurant")
|
|
25
|
+
.to_return(body: {}.to_json)
|
|
26
|
+
stub_request(:get, "https://attributes/bar?limit=100")
|
|
27
|
+
.to_return(body: {
|
|
28
|
+
group: {
|
|
29
|
+
href: 'https://group/general'
|
|
30
|
+
}
|
|
31
|
+
}.to_json)
|
|
32
|
+
stub_request(:get, "https://attributes/cafe?limit=100")
|
|
33
|
+
.to_return(body: {
|
|
34
|
+
group: {
|
|
35
|
+
href: 'https://group/general'
|
|
36
|
+
}
|
|
37
|
+
}.to_json)
|
|
38
|
+
stub_request(:get, "https://group/general?limit=100&status=active")
|
|
39
|
+
.to_return(body: {
|
|
40
|
+
name: 'General'
|
|
41
|
+
}.to_json)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context 'missing referenced options due to none existance of include' do
|
|
45
|
+
|
|
46
|
+
it 'does not raise when trying to merge options with the options block' do
|
|
47
|
+
LHS.options(throttle: { break: '80%' }) do
|
|
48
|
+
record = Record
|
|
49
|
+
.references(place_attributes: { group: { params: { status: 'active' } } })
|
|
50
|
+
.includes([{ place_attributes: :group }])
|
|
51
|
+
.find(1)
|
|
52
|
+
expect(record.place_attributes[0].group.name).to eq 'General'
|
|
53
|
+
expect(record.place_attributes[1].group).to eq nil
|
|
54
|
+
expect(record.place_attributes[2].group.name).to eq 'General'
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -76,7 +76,7 @@ describe LHS::Record do
|
|
|
76
76
|
}.to_json
|
|
77
77
|
)
|
|
78
78
|
|
|
79
|
-
stub_request(:get, 'http://datastore/customers/1/users/1
|
|
79
|
+
stub_request(:get, 'http://datastore/customers/1/users/1')
|
|
80
80
|
.with(headers: { 'Authentication' => 'Bearer 123' })
|
|
81
81
|
.to_return(body: { href: 'http://datastore/users/1', name: 'Elizabeth Baker' }.to_json)
|
|
82
82
|
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:
|
|
4
|
+
version: 25.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- https://github.com/local-ch/lhs/graphs/contributors
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-
|
|
11
|
+
date: 2020-11-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activemodel
|
|
@@ -47,7 +47,7 @@ dependencies:
|
|
|
47
47
|
version: 12.1.1
|
|
48
48
|
- - "<"
|
|
49
49
|
- !ruby/object:Gem::Version
|
|
50
|
-
version: '
|
|
50
|
+
version: '14'
|
|
51
51
|
type: :runtime
|
|
52
52
|
prerelease: false
|
|
53
53
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -57,7 +57,7 @@ dependencies:
|
|
|
57
57
|
version: 12.1.1
|
|
58
58
|
- - "<"
|
|
59
59
|
- !ruby/object:Gem::Version
|
|
60
|
-
version: '
|
|
60
|
+
version: '14'
|
|
61
61
|
- !ruby/object:Gem::Dependency
|
|
62
62
|
name: local_uri
|
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -263,6 +263,7 @@ files:
|
|
|
263
263
|
- cider-ci/task_components/rspec.yml
|
|
264
264
|
- cider-ci/task_components/rubocop.yml
|
|
265
265
|
- cider-ci/task_components/ruby.yml
|
|
266
|
+
- docs/accessing-data-in-lhs.png
|
|
266
267
|
- friday.yml
|
|
267
268
|
- lhs.gemspec
|
|
268
269
|
- lib/lhs.rb
|
|
@@ -388,6 +389,7 @@ files:
|
|
|
388
389
|
- spec/dummy/app/mailers/.keep
|
|
389
390
|
- spec/dummy/app/models/.keep
|
|
390
391
|
- spec/dummy/app/models/concerns/.keep
|
|
392
|
+
- spec/dummy/app/models/concerns/dummy_customer/some_concern.rb
|
|
391
393
|
- spec/dummy/app/models/dummy_customer.rb
|
|
392
394
|
- spec/dummy/app/models/dummy_record.rb
|
|
393
395
|
- spec/dummy/app/models/dummy_record_with_auto_oauth_provider.rb
|
|
@@ -503,7 +505,9 @@ files:
|
|
|
503
505
|
- spec/record/href_for_spec.rb
|
|
504
506
|
- spec/record/ignore_errors_spec.rb
|
|
505
507
|
- spec/record/immutable_chains_spec.rb
|
|
508
|
+
- spec/record/includes_expanded_spec.rb
|
|
506
509
|
- spec/record/includes_first_page_spec.rb
|
|
510
|
+
- spec/record/includes_missing_spec.rb
|
|
507
511
|
- spec/record/includes_spec.rb
|
|
508
512
|
- spec/record/includes_warning_spec.rb
|
|
509
513
|
- spec/record/item_key_spec.rb
|
|
@@ -552,7 +556,7 @@ homepage: https://github.com/local-ch/lhs
|
|
|
552
556
|
licenses:
|
|
553
557
|
- GPL-3.0
|
|
554
558
|
metadata: {}
|
|
555
|
-
post_install_message:
|
|
559
|
+
post_install_message:
|
|
556
560
|
rdoc_options: []
|
|
557
561
|
require_paths:
|
|
558
562
|
- lib
|
|
@@ -568,8 +572,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
568
572
|
version: '0'
|
|
569
573
|
requirements:
|
|
570
574
|
- Ruby >= 2.3.0
|
|
571
|
-
rubygems_version: 3.0.
|
|
572
|
-
signing_key:
|
|
575
|
+
rubygems_version: 3.0.6
|
|
576
|
+
signing_key:
|
|
573
577
|
specification_version: 4
|
|
574
578
|
summary: 'REST services accelerator: Rails gem providing an easy, active-record-like
|
|
575
579
|
interface for http (hypermedia) json services'
|
|
@@ -617,6 +621,7 @@ test_files:
|
|
|
617
621
|
- spec/dummy/app/mailers/.keep
|
|
618
622
|
- spec/dummy/app/models/.keep
|
|
619
623
|
- spec/dummy/app/models/concerns/.keep
|
|
624
|
+
- spec/dummy/app/models/concerns/dummy_customer/some_concern.rb
|
|
620
625
|
- spec/dummy/app/models/dummy_customer.rb
|
|
621
626
|
- spec/dummy/app/models/dummy_record.rb
|
|
622
627
|
- spec/dummy/app/models/dummy_record_with_auto_oauth_provider.rb
|
|
@@ -732,7 +737,9 @@ test_files:
|
|
|
732
737
|
- spec/record/href_for_spec.rb
|
|
733
738
|
- spec/record/ignore_errors_spec.rb
|
|
734
739
|
- spec/record/immutable_chains_spec.rb
|
|
740
|
+
- spec/record/includes_expanded_spec.rb
|
|
735
741
|
- spec/record/includes_first_page_spec.rb
|
|
742
|
+
- spec/record/includes_missing_spec.rb
|
|
736
743
|
- spec/record/includes_spec.rb
|
|
737
744
|
- spec/record/includes_warning_spec.rb
|
|
738
745
|
- spec/record/item_key_spec.rb
|