lhs 3.0.5 → 3.1.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 -0
- data/lib/lhs/concerns/record/pagination.rb +36 -0
- data/lib/lhs/record.rb +1 -0
- data/lib/lhs/version.rb +1 -1
- data/spec/record/pagination_spec.rb +60 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b4d8da57cb83a4edce0d5a3ced7289528fc3aeb
|
4
|
+
data.tar.gz: cd8ca6b468931ce8a677ee0ec686a04c05798d75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f4f26c5cc042bf73e69c0ff021e5ce5b32d4fabf5afe8b692b5a6ececad255759aa86eda2d78a21031f0bca8481769bce809ebf45535c8eab478b8fdbea37e0
|
7
|
+
data.tar.gz: 9672198becdb370e7775f8a922e613ee1ee7f28936f13672b936619e582c0cec3127bec258250e2dd14fa24db439e25d02af25b2a662d34cffd81e7faf1e2f58
|
data/README.md
CHANGED
@@ -331,3 +331,19 @@ Feedback.where(limit: 50, offset: 51)
|
|
331
331
|
`total` provides total amount of items (even if paginated).
|
332
332
|
`limit` provides amount of items per page.
|
333
333
|
`offset` provides how many items where skipped to start the current page.
|
334
|
+
|
335
|
+
## Partial Kaminari support
|
336
|
+
|
337
|
+
LHS implements an interface that makes it partially working with Kaminari.
|
338
|
+
|
339
|
+
For example, you can use kaminari to render paginations based on LHS Records:
|
340
|
+
|
341
|
+
```ruby
|
342
|
+
# controller
|
343
|
+
@items = Record.where(offset: offset, limit: limit)
|
344
|
+
```
|
345
|
+
|
346
|
+
```ruby
|
347
|
+
# view
|
348
|
+
= paginate @items
|
349
|
+
```
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
3
|
+
class LHS::Record
|
4
|
+
|
5
|
+
module Pagination
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
def current_page
|
9
|
+
offset + 1
|
10
|
+
end
|
11
|
+
|
12
|
+
def first_page
|
13
|
+
1
|
14
|
+
end
|
15
|
+
|
16
|
+
def last_page
|
17
|
+
total_pages
|
18
|
+
end
|
19
|
+
|
20
|
+
def prev_page
|
21
|
+
current_page - 1
|
22
|
+
end
|
23
|
+
|
24
|
+
def next_page
|
25
|
+
current_page + 1
|
26
|
+
end
|
27
|
+
|
28
|
+
def limit_value
|
29
|
+
limit
|
30
|
+
end
|
31
|
+
|
32
|
+
def total_pages
|
33
|
+
total / limit
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/lhs/record.rb
CHANGED
data/lib/lhs/version.rb
CHANGED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe LHS::Record do
|
4
|
+
context 'pagination' do
|
5
|
+
let(:datastore) { 'http://local.ch/v2' }
|
6
|
+
let(:record) { Feedback.where(entry_id: 1) }
|
7
|
+
let(:total) { 200 }
|
8
|
+
let(:total_pages) { total / limit }
|
9
|
+
let(:current_page) { offset + 1 }
|
10
|
+
let(:prev_page) { current_page - 1 }
|
11
|
+
let(:next_page) { current_page + 1 }
|
12
|
+
let(:offset) { 0 }
|
13
|
+
let(:limit) { 10 }
|
14
|
+
let(:body_json) do
|
15
|
+
{
|
16
|
+
items: [],
|
17
|
+
total: total,
|
18
|
+
offset: offset,
|
19
|
+
limit: limit
|
20
|
+
}.to_json
|
21
|
+
end
|
22
|
+
|
23
|
+
before(:each) do
|
24
|
+
LHC.config.placeholder('datastore', datastore)
|
25
|
+
class Feedback < LHS::Record
|
26
|
+
endpoint ':datastore/feedbacks'
|
27
|
+
end
|
28
|
+
stub_request(:get, 'http://local.ch/v2/feedbacks?entry_id=1')
|
29
|
+
.and_return(body: body_json)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'responds to limit_value' do
|
33
|
+
expect(record.limit_value).to eq(limit)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'responds to total_pages' do
|
37
|
+
expect(record.total_pages).to eq(total_pages)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'responds to current_page' do
|
41
|
+
expect(record.current_page).to eq(current_page)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'responds to first_page' do
|
45
|
+
expect(record.first_page).to eq(1)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'responds to last_page' do
|
49
|
+
expect(record.last_page).to eq(total_pages)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'responds to prev_page' do
|
53
|
+
expect(record.prev_page).to eq(prev_page)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'responds to next_page' do
|
57
|
+
expect(record.next_page).to eq(next_page)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
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: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- https://github.com/local-ch/lhs/graphs/contributors
|
@@ -165,6 +165,7 @@ files:
|
|
165
165
|
- lib/lhs/concerns/record/includes.rb
|
166
166
|
- lib/lhs/concerns/record/mapping.rb
|
167
167
|
- lib/lhs/concerns/record/model.rb
|
168
|
+
- lib/lhs/concerns/record/pagination.rb
|
168
169
|
- lib/lhs/concerns/record/request.rb
|
169
170
|
- lib/lhs/concerns/record/where.rb
|
170
171
|
- lib/lhs/data.rb
|
@@ -257,6 +258,7 @@ files:
|
|
257
258
|
- spec/record/mapping_spec.rb
|
258
259
|
- spec/record/model_name_spec.rb
|
259
260
|
- spec/record/new_spec.rb
|
261
|
+
- spec/record/pagination_spec.rb
|
260
262
|
- spec/record/request_spec.rb
|
261
263
|
- spec/record/select_spec.rb
|
262
264
|
- spec/record/to_json_spec.rb
|
@@ -376,6 +378,7 @@ test_files:
|
|
376
378
|
- spec/record/mapping_spec.rb
|
377
379
|
- spec/record/model_name_spec.rb
|
378
380
|
- spec/record/new_spec.rb
|
381
|
+
- spec/record/pagination_spec.rb
|
379
382
|
- spec/record/request_spec.rb
|
380
383
|
- spec/record/select_spec.rb
|
381
384
|
- spec/record/to_json_spec.rb
|