lhs 24.1.0.pre.2 → 25.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -1
- data/docs/accessing-data-in-lhs.png +0 -0
- data/lhs.gemspec +1 -1
- data/lib/lhs/concerns/autoload_records.rb +1 -1
- 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/record/compact_spec.rb +30 -7
- data/spec/record/includes_expanded_spec.rb +37 -0
- data/spec/record/references_spec.rb +43 -0
- metadata +12 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca4c950dd6c2640b9bc05fc571ab0e54c06c2a796a1f004cd5fdb1898f186785
|
4
|
+
data.tar.gz: 0ce0b9625865a63398334af094e9aa13abe7659c1a973e46bd60256c4ae5e343
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4333ef227de49a40508d2ae4a91ef25f3b4b40f94853b285099c8bd3e5a14104d2cd939aa058690a72bdd67c320bd6c21f93bb311ba001c5ec859d18a959d81
|
7
|
+
data.tar.gz: 0c0f9fb7860dd1787a0c206068f51ef757d49943b607395993d0b0f0547424c00722fb7fd35b3e3d234fae736e984e84749e5ed9d679a1dd7169715806d28a14
|
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`
|
@@ -1698,7 +1702,7 @@ record.partial_update(recommended: true)
|
|
1698
1702
|
|
1699
1703
|
```
|
1700
1704
|
```
|
1701
|
-
POST https://service.example.com/records/1z-5r1fkaj { body: "{ '
|
1705
|
+
POST https://service.example.com/records/1z-5r1fkaj { body: "{ 'recommended': true }" }
|
1702
1706
|
```
|
1703
1707
|
|
1704
1708
|
-> See [record validation](#record-validation) for how to handle validation errors when updating records.
|
@@ -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
|
+
![diagram](docs/accessing-data-in-lhs.png)
|
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'
|
@@ -41,7 +41,7 @@ module AutoloadRecords
|
|
41
41
|
|
42
42
|
def self.require_inheriting_records(parents)
|
43
43
|
model_files.each do |file|
|
44
|
-
next if parents.none? { |parent| File.read(file).match(parent) }
|
44
|
+
next if parents.none? { |parent| File.read(file).match(/\b#{parent}\b/) }
|
45
45
|
require_dependency file
|
46
46
|
end
|
47
47
|
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.1
|
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-10-16 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
|
@@ -503,6 +504,7 @@ files:
|
|
503
504
|
- spec/record/href_for_spec.rb
|
504
505
|
- spec/record/ignore_errors_spec.rb
|
505
506
|
- spec/record/immutable_chains_spec.rb
|
507
|
+
- spec/record/includes_expanded_spec.rb
|
506
508
|
- spec/record/includes_first_page_spec.rb
|
507
509
|
- spec/record/includes_spec.rb
|
508
510
|
- spec/record/includes_warning_spec.rb
|
@@ -552,7 +554,7 @@ homepage: https://github.com/local-ch/lhs
|
|
552
554
|
licenses:
|
553
555
|
- GPL-3.0
|
554
556
|
metadata: {}
|
555
|
-
post_install_message:
|
557
|
+
post_install_message:
|
556
558
|
rdoc_options: []
|
557
559
|
require_paths:
|
558
560
|
- lib
|
@@ -563,13 +565,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
563
565
|
version: 2.3.0
|
564
566
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
565
567
|
requirements:
|
566
|
-
- - "
|
568
|
+
- - ">="
|
567
569
|
- !ruby/object:Gem::Version
|
568
|
-
version:
|
570
|
+
version: '0'
|
569
571
|
requirements:
|
570
572
|
- Ruby >= 2.3.0
|
571
573
|
rubygems_version: 3.0.6
|
572
|
-
signing_key:
|
574
|
+
signing_key:
|
573
575
|
specification_version: 4
|
574
576
|
summary: 'REST services accelerator: Rails gem providing an easy, active-record-like
|
575
577
|
interface for http (hypermedia) json services'
|
@@ -732,6 +734,7 @@ test_files:
|
|
732
734
|
- spec/record/href_for_spec.rb
|
733
735
|
- spec/record/ignore_errors_spec.rb
|
734
736
|
- spec/record/immutable_chains_spec.rb
|
737
|
+
- spec/record/includes_expanded_spec.rb
|
735
738
|
- spec/record/includes_first_page_spec.rb
|
736
739
|
- spec/record/includes_spec.rb
|
737
740
|
- spec/record/includes_warning_spec.rb
|