lhs 24.1.0 → 25.0.2
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/concerns/autoload_records.rb +4 -2
- data/lib/lhs/concerns/collection/internal_collection.rb +12 -4
- data/lib/lhs/concerns/record/request.rb +1 -1
- 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 +30 -7
- data/spec/record/includes_expanded_spec.rb +37 -0
- data/spec/record/references_spec.rb +43 -0
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '030995aefe88b5d0494d0e7ccaa760eb2a67d8ebf728ce4aaaa8646ca5b130ef'
|
4
|
+
data.tar.gz: af0e530a38ff5c816a797613506b40c996f58aea8c391ca59099d1ee6152ce00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70859dbf4582c03d84edeb5aa6b750ee76a4908e2bd43e9c324b4ab8ca318da457087f2b95d3c433e570f48d2ee4a6cc691dd821830c82f86acc44f7e8ff4652
|
7
|
+
data.tar.gz: ab20d6595519d82cf47a9b203f0e246062ce6d611c9997c4ae50cc3fb33c0b1378c911415df845ddbc2f714c98bc05d63c562e5364227a7ccba1a573af9f1954
|
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'
|
@@ -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
|
@@ -47,7 +47,7 @@ class LHS::Collection < LHS::Proxy
|
|
47
47
|
if item.is_a?(LHS::Data) && item._request && !item._request.response.success?
|
48
48
|
nil
|
49
49
|
else
|
50
|
-
item
|
50
|
+
cast_item(item)
|
51
51
|
end
|
52
52
|
end.compact
|
53
53
|
end
|
@@ -55,10 +55,18 @@ class LHS::Collection < LHS::Proxy
|
|
55
55
|
private
|
56
56
|
|
57
57
|
def cast_item(item)
|
58
|
-
record_by_href = LHS::Record.for_url(item[:href]) if item[:href]
|
59
58
|
data = LHS::Data.new(item, @parent, @record)
|
60
|
-
|
61
|
-
|
59
|
+
(record_by_href(item) || @record)&.new(data) || data
|
60
|
+
end
|
61
|
+
|
62
|
+
def record_by_href(item)
|
63
|
+
return if plain_value?(item) || item[:href].blank?
|
64
|
+
|
65
|
+
LHS::Record.for_url(item[:href])
|
66
|
+
end
|
67
|
+
|
68
|
+
def plain_value?(item)
|
69
|
+
item.is_a?(String) || item.is_a?(Numeric) || item.is_a?(TrueClass) || item.is_a?(FalseClass)
|
62
70
|
end
|
63
71
|
end
|
64
72
|
end
|
@@ -120,7 +120,7 @@ class LHS::Record
|
|
120
120
|
options = extend_with_reference(options, reference)
|
121
121
|
addition = load_include(options, data, sub_includes, reference)
|
122
122
|
data.extend!(addition, included)
|
123
|
-
expand_addition!(data, included,
|
123
|
+
expand_addition!(data, included, reference) unless expanded_data?(addition)
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
data/lib/lhs/version.rb
CHANGED
data/spec/record/compact_spec.rb
CHANGED
@@ -6,6 +6,11 @@ describe LHS::Record do
|
|
6
6
|
before do
|
7
7
|
class Place < LHS::Record
|
8
8
|
endpoint 'http://datastore/places/{id}'
|
9
|
+
endpoint 'http://datastore/users/{user_id}/places/{id}'
|
10
|
+
|
11
|
+
def display_name
|
12
|
+
"*#{name}*"
|
13
|
+
end
|
9
14
|
end
|
10
15
|
|
11
16
|
class User < LHS::Record
|
@@ -24,14 +29,24 @@ describe LHS::Record do
|
|
24
29
|
items: [
|
25
30
|
{
|
26
31
|
href: 'http://datastore/users/123/places/789'
|
32
|
+
}, {
|
33
|
+
href: 'http://datastore/users/123/places/790'
|
27
34
|
}
|
28
35
|
],
|
29
|
-
total:
|
36
|
+
total: 2,
|
30
37
|
offset: 0,
|
31
38
|
limit: 10
|
32
39
|
}.to_json)
|
33
40
|
|
34
|
-
stub_request(:get, 'http://datastore/users/123/places/789
|
41
|
+
stub_request(:get, 'http://datastore/users/123/places/789')
|
42
|
+
.to_return(
|
43
|
+
body: {
|
44
|
+
href: 'http://datastore/users/123/places/789?limit=100',
|
45
|
+
name: 'Mc Donalds'
|
46
|
+
}.to_json
|
47
|
+
)
|
48
|
+
|
49
|
+
stub_request(:get, 'http://datastore/users/123/places/790')
|
35
50
|
.to_return(
|
36
51
|
status: 404,
|
37
52
|
body: {
|
@@ -51,17 +66,25 @@ describe LHS::Record do
|
|
51
66
|
end
|
52
67
|
|
53
68
|
context '.compact' do
|
54
|
-
|
55
69
|
it 'removes linked resouces which could not get fetched' do
|
56
|
-
expect(places.compact.length).to eq
|
57
|
-
expect(places.length).not_to eq
|
70
|
+
expect(places.compact.length).to eq 1
|
71
|
+
expect(places.length).not_to eq 1 # leaves the original intact
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'record casting' do
|
76
|
+
let(:expected_display_name) { '*Mc Donalds*' }
|
77
|
+
|
78
|
+
it 'finds the right record class' do
|
79
|
+
expect(places.first.display_name).to eq expected_display_name
|
80
|
+
expect(places.compact.map(&:display_name)).to eq [expected_display_name]
|
58
81
|
end
|
59
82
|
end
|
60
83
|
|
61
84
|
context '.compact!' do
|
62
85
|
it 'removes linked resouces which could not get fetched' do
|
63
|
-
expect(places.compact!.length).to eq
|
64
|
-
expect(places.length).to eq
|
86
|
+
expect(places.compact!.length).to eq 1
|
87
|
+
expect(places.length).to eq 1 # and changes the original intact
|
65
88
|
end
|
66
89
|
end
|
67
90
|
end
|
@@ -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
|
@@ -8,6 +8,14 @@ describe LHS::Record do
|
|
8
8
|
class Customer < LHS::Record
|
9
9
|
endpoint 'http://datastore/customers/{id}'
|
10
10
|
end
|
11
|
+
|
12
|
+
class User < LHS::Record
|
13
|
+
endpoint 'http://datastore/users/{id}'
|
14
|
+
endpoint 'http://datastore/customers/{customer_id}/users/{id}'
|
15
|
+
def reversed_name
|
16
|
+
name.split.reverse.join(' ')
|
17
|
+
end
|
18
|
+
end
|
11
19
|
end
|
12
20
|
|
13
21
|
let!(:customer_request) do
|
@@ -18,6 +26,9 @@ describe LHS::Record do
|
|
18
26
|
},
|
19
27
|
'contact_addresses' => {
|
20
28
|
'href' => "http://datastore/contact_addresses"
|
29
|
+
},
|
30
|
+
'users' => {
|
31
|
+
'href' => 'http://datastore/customers/1/users'
|
21
32
|
}
|
22
33
|
}.to_json)
|
23
34
|
end
|
@@ -49,5 +60,37 @@ describe LHS::Record do
|
|
49
60
|
assert_requested(electronic_addresses_request)
|
50
61
|
assert_requested(contact_addresses_request)
|
51
62
|
end
|
63
|
+
|
64
|
+
describe 'mapping related classes correctly' do
|
65
|
+
before do
|
66
|
+
stub_request(:get, 'http://datastore/customers/1/users?limit=100').to_return(
|
67
|
+
status: 200,
|
68
|
+
body: {
|
69
|
+
href: 'http://datastore/customers/1/users?offset=0&limit=100',
|
70
|
+
items: [
|
71
|
+
{ href: 'http://datastore/customers/1/users/1' }
|
72
|
+
],
|
73
|
+
total: 1,
|
74
|
+
offset: 0,
|
75
|
+
limit: 10
|
76
|
+
}.to_json
|
77
|
+
)
|
78
|
+
|
79
|
+
stub_request(:get, 'http://datastore/customers/1/users/1')
|
80
|
+
.with(headers: { 'Authentication' => 'Bearer 123' })
|
81
|
+
.to_return(body: { href: 'http://datastore/users/1', name: 'Elizabeth Baker' }.to_json)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'maps correctly' do
|
85
|
+
users = Customer
|
86
|
+
.includes(:users)
|
87
|
+
.references(users: referencing_options)
|
88
|
+
.find(1)
|
89
|
+
.users
|
90
|
+
|
91
|
+
expect(users.first.reversed_name).to be_present
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
52
95
|
end
|
53
96
|
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.2
|
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: 2020-
|
11
|
+
date: 2020-10-30 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,6 +505,7 @@ 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
|
507
510
|
- spec/record/includes_spec.rb
|
508
511
|
- spec/record/includes_warning_spec.rb
|
@@ -617,6 +620,7 @@ test_files:
|
|
617
620
|
- spec/dummy/app/mailers/.keep
|
618
621
|
- spec/dummy/app/models/.keep
|
619
622
|
- spec/dummy/app/models/concerns/.keep
|
623
|
+
- spec/dummy/app/models/concerns/dummy_customer/some_concern.rb
|
620
624
|
- spec/dummy/app/models/dummy_customer.rb
|
621
625
|
- spec/dummy/app/models/dummy_record.rb
|
622
626
|
- spec/dummy/app/models/dummy_record_with_auto_oauth_provider.rb
|
@@ -732,6 +736,7 @@ test_files:
|
|
732
736
|
- spec/record/href_for_spec.rb
|
733
737
|
- spec/record/ignore_errors_spec.rb
|
734
738
|
- spec/record/immutable_chains_spec.rb
|
739
|
+
- spec/record/includes_expanded_spec.rb
|
735
740
|
- spec/record/includes_first_page_spec.rb
|
736
741
|
- spec/record/includes_spec.rb
|
737
742
|
- spec/record/includes_warning_spec.rb
|