lhs 7.2.5 → 7.3.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 +9 -0
- data/lib/lhs/collection.rb +2 -1
- data/lib/lhs/pagination.rb +8 -0
- data/lib/lhs/version.rb +1 -1
- data/spec/record/pagination_links_spec.rb +70 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af216b090a45a83dea5acd0a3af1492932999f59
|
4
|
+
data.tar.gz: a46a8f31fe3f31f577fcb97585c13f23739128da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca258fd031bec87565cc8db528d7aeb6887719cba1bc96eb62b6a9ed09b3c70d0b3c9d99c92750bd187cf26ea70e1d381c7be641ee8c27e1fe772ef5eead1fcd
|
7
|
+
data.tar.gz: 863c29e31f101e9b8acb69d274998e48503d71176ac26bcd3001e18d6f05fce49daf0c85462fec705e12482b1589aedfaee8bc626056c62afea7f99e8caa21fd
|
data/README.md
CHANGED
@@ -766,6 +766,15 @@ The kaminari’s page parameter is in params[:page]. For example, you can use ka
|
|
766
766
|
= paginate @items
|
767
767
|
```
|
768
768
|
|
769
|
+
### Pagination Links
|
770
|
+
|
771
|
+
When endpoints provide indicators for current page position with links (like `next` and `previous`), LHS provides some functionalities to interact/use those links/information:
|
772
|
+
|
773
|
+
`next?` Tells you if there is a next link or not.
|
774
|
+
|
775
|
+
`previous?` Tells you if there is a previous link or not.
|
776
|
+
|
777
|
+
|
769
778
|
## Automatic Detection of Collections
|
770
779
|
|
771
780
|
How to configure endpoints for automatic collection detection?
|
data/lib/lhs/collection.rb
CHANGED
@@ -9,7 +9,8 @@ class LHS::Collection < LHS::Proxy
|
|
9
9
|
|
10
10
|
delegate :select, :length, :size, to: :_collection
|
11
11
|
delegate :_record, :_raw, to: :_data
|
12
|
-
delegate :limit, :count, :total, :
|
12
|
+
delegate :limit, :count, :total, :offset, :current_page, :start,
|
13
|
+
:next?, :previous?, to: :_pagination
|
13
14
|
|
14
15
|
def _pagination
|
15
16
|
_record.pagination(_data)
|
data/lib/lhs/pagination.rb
CHANGED
data/lib/lhs/version.rb
CHANGED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe LHS::Record do
|
4
|
+
context 'pagination links' do
|
5
|
+
before(:each) do
|
6
|
+
class Customer < LHS::Record
|
7
|
+
endpoint 'http://datastore/customer'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
let!(:request) do
|
12
|
+
stub_request(:get, "http://datastore/customer#{query}")
|
13
|
+
.to_return(body: body)
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:query) { "?name=#{name}&page=#{page}" }
|
17
|
+
|
18
|
+
let(:customers) do
|
19
|
+
Customer.where(name: name, page: page)
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'next and previous link is present' do
|
23
|
+
let(:name) { 'Simpl' }
|
24
|
+
let(:page) { 2 }
|
25
|
+
let(:body) do
|
26
|
+
{
|
27
|
+
next: "http://datastore/customer?name=#{name}&page=3",
|
28
|
+
previous: "http://datastore/customer?name=#{name}&page=1",
|
29
|
+
items: [{ name: 'Simplificator' }]
|
30
|
+
}.to_json
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'tells me that there is a next link' do
|
34
|
+
expect(customers.next?).to eq true
|
35
|
+
expect(customers.previous?).to eq true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'next link is present, previous is not' do
|
40
|
+
let(:name) { 'Simpl' }
|
41
|
+
let(:page) { 2 }
|
42
|
+
let(:body) do
|
43
|
+
{
|
44
|
+
next: "http://datastore/customer?name=#{name}&page=3",
|
45
|
+
items: [{ name: 'Simplificator' }]
|
46
|
+
}.to_json
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'tells me that there is a next link' do
|
50
|
+
expect(customers.next?).to eq true
|
51
|
+
expect(customers.previous?).to eq false
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'no next link and no previous link is present' do
|
56
|
+
let(:name) { 'Simplificator' }
|
57
|
+
let(:page) { 1 }
|
58
|
+
let(:body) do
|
59
|
+
{
|
60
|
+
items: [{ name: 'Simplificator' }]
|
61
|
+
}.to_json
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'tells me that there is no next link' do
|
65
|
+
expect(customers.next?).to eq false
|
66
|
+
expect(customers.previous?).to eq false
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
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: 7.
|
4
|
+
version: 7.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- https://github.com/local-ch/lhs/graphs/contributors
|
@@ -335,6 +335,7 @@ files:
|
|
335
335
|
- spec/record/options_spec.rb
|
336
336
|
- spec/record/paginatable_collection_spec.rb
|
337
337
|
- spec/record/pagination_chain_spec.rb
|
338
|
+
- spec/record/pagination_links_spec.rb
|
338
339
|
- spec/record/pagination_spec.rb
|
339
340
|
- spec/record/persisted_spec.rb
|
340
341
|
- spec/record/references_spec.rb
|
@@ -487,6 +488,7 @@ test_files:
|
|
487
488
|
- spec/record/options_spec.rb
|
488
489
|
- spec/record/paginatable_collection_spec.rb
|
489
490
|
- spec/record/pagination_chain_spec.rb
|
491
|
+
- spec/record/pagination_links_spec.rb
|
490
492
|
- spec/record/pagination_spec.rb
|
491
493
|
- spec/record/persisted_spec.rb
|
492
494
|
- spec/record/references_spec.rb
|