jsom-pagination 0.1.3 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9683eaf9e2075be921220150497c259f70a86364bed959b44439baa69d967434
4
- data.tar.gz: b0d4807a2c199739dea43e1cb381b8439621c838561939f14fff091d1c535e1f
3
+ metadata.gz: 6415e49a04f8885c064851aa701c1d27c15dd304cebb0c631d0b3940e8982bb0
4
+ data.tar.gz: c3504379d9aae6c6b719bf8bbd01a2cf7f7304a87f29e805f90d86a997851f29
5
5
  SHA512:
6
- metadata.gz: 870e1557784ce98ef46bc8f7d7e86b84ebc3bc7ad04d74de49963160ceb10046ef21b4ce60f9d7573582ed2282819e1246304f0cdbe7b5e73c79649365bf3dbb
7
- data.tar.gz: 4c08dcc05cf729b7c53a760ae7e1e28aabe25690bc671858ec54502034d9c96f3cbbcaf7a7321cc7bb328937a4aeffc4fdb3f0b74b367b65b6f936c681dcd122
6
+ metadata.gz: 3d2e7ea3717ef733bbf6f582702dec2f91cae7794d39534fb6dc1e8f59c8e72524f091869a91d4c0cd0f1a719bce6a8e010a887d8137c7dbd5694f2e6542804f
7
+ data.tar.gz: ee117de26a9f788416e2f7c1658a732bee86beff2f02efb4240b72193c7336aceaf12724dfe4a5af97a6cda79defefd35bb8206569e769f9bc36c9e1b902018e
@@ -8,13 +8,17 @@ jobs:
8
8
  build:
9
9
  name: Build + Publish
10
10
  runs-on: ubuntu-latest
11
+ strategy:
12
+ matrix:
13
+ ruby-version: ['3.0', '3.1', '3.2']
11
14
 
12
15
  steps:
13
16
  - uses: actions/checkout@v2
14
- - name: Set up Ruby 2.7.1
15
- uses: actions/setup-ruby@v1
17
+ - name: Set up Ruby
18
+ uses: ruby/setup-ruby@v1.147.0
16
19
  with:
17
- ruby-version: 2.7.1
20
+ ruby-version: ${{ matrix.ruby-version }}
21
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
18
22
  - name: Run tests
19
23
  run: |
20
24
  bundle install
@@ -10,20 +10,24 @@ jobs:
10
10
  build:
11
11
  name: Build + Test
12
12
  runs-on: ubuntu-latest
13
+ strategy:
14
+ matrix:
15
+ ruby-version: ['3.0', '3.1', '3.2']
13
16
 
14
17
  steps:
15
18
  - uses: actions/checkout@v2
16
- - name: Set up Ruby 2.7.1
17
- uses: actions/setup-ruby@v1
19
+ - name: Set up Ruby
20
+ uses: ruby/setup-ruby@v1.147.0
18
21
  with:
19
- ruby-version: 2.7.1
22
+ ruby-version: ${{ matrix.ruby-version }}
23
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
20
24
  - name: Run tests
21
25
  run: |
22
26
  bundle install
23
27
  CI=true bundle exec rspec
24
- - name: Upload report
25
- run: |
26
- mv ./coverage/coverage.xml cobertura.xml
27
- bash <(curl -Ls https://coverage.codacy.com/get.sh) report
28
- env:
29
- CODACY_PROJECT_TOKEN: ${{secrets.CODACY_PROJECT_TOKEN}}
28
+ # - name: Upload report
29
+ # run: |
30
+ # mv ./coverage/coverage.xml cobertura.xml
31
+ # bash <(curl -Ls https://coverage.codacy.com/get.sh) report
32
+ # env:
33
+ # CODACY_PROJECT_TOKEN: ${{secrets.CODACY_PROJECT_TOKEN}}
data/.gitignore CHANGED
@@ -13,3 +13,8 @@
13
13
  .DS_Store
14
14
  package.json
15
15
  package-lock.json
16
+
17
+ #rubocop qa-tools default rules
18
+ .rubocop-https*
19
+
20
+ /jsom-pagination*.gem
@@ -0,0 +1,12 @@
1
+ # These are all the cops that are disabled in the default configuration.
2
+
3
+ Style/Copyright:
4
+ Enabled: false
5
+
6
+ Metrics/BlockLength:
7
+ Exclude:
8
+ - "spec/**/*_spec.rb"
9
+
10
+ Metrics/ModuleLength:
11
+ Exclude:
12
+ - "spec/**/*_spec.rb"
data/.rubocop.yml CHANGED
@@ -1,7 +1,11 @@
1
- Metrics/BlockLength:
2
- Exclude:
3
- - "spec/**/*_spec.rb"
1
+ inherit_from:
2
+ - https://raw.githubusercontent.com/yousty/qa-tools/master/rubocop/base/.rubocop.yml # common enabled rules
3
+ - https://raw.githubusercontent.com/yousty/qa-tools/master/rubocop/base/.rubocop.disabled.yml # common disabled rules
4
+ - .rubocop.disabled.yml # project specific disabled rules
4
5
 
5
- Metrics/ModuleLength:
6
- Exclude:
7
- - "spec/**/*_spec.rb"
6
+ # project specific overwritten rules
7
+
8
+ # example:
9
+ # Layout/LineLength:
10
+ # Max: 100
11
+ # AllowHeredoc: true
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.7.1
1
+ ruby-3.2.2
data/README.md CHANGED
@@ -82,6 +82,88 @@ options = { meta: paginated.meta.to_h, links: paginated.links.to_h }
82
82
  render json: serializer.new(paginated.items, options)
83
83
  ```
84
84
 
85
+ ### Summary
86
+
87
+ Using the information above, you can put everything all together by using [jsom-pagination](https://github.com/useo-pl/jsom-pagination) in a ruby framework of your choice.
88
+
89
+ Below is an illustration in [Rails](https://rubyonrails.org/):
90
+
91
+ ```ruby
92
+ # app/controllers/concerns/paginable.rb
93
+ module Paginable
94
+ extend ActiveSupport::Concern
95
+
96
+ def paginator
97
+ JSOM::Pagination::Paginator.new
98
+ end
99
+
100
+ def pagination_params
101
+ params.permit![:page] # defaults to 20 pages
102
+ end
103
+
104
+ def paginate(collection)
105
+ paginator.call(collection, params: pagination_params, base_url: request.url)
106
+ end
107
+
108
+ def render_collection(paginated)
109
+ options = {
110
+ # meta: paginated.meta.to_h, # Will get total pages, total count, etc.
111
+ links: paginated.links.to_h
112
+ }
113
+ paginated_result = serializer.new(paginated.items, options)
114
+
115
+ render json: paginated_result
116
+ end
117
+ end
118
+ ```
119
+
120
+ ```ruby
121
+ # app/controllers/articles_controllers.rb
122
+ class ArtclesController < ApplicationController
123
+ include Paginable
124
+
125
+ def index
126
+ articles = articles = Article.order('created_at DESC')
127
+ paginated = paginate(articles)
128
+
129
+ articles.present? ? render_collection(paginated) : :not_found
130
+ end
131
+
132
+ private
133
+
134
+ def serializer
135
+ ArticleSerializer
136
+ end
137
+ end
138
+ ```
139
+
140
+ The response from the paginated json will look like below:
141
+
142
+ ```json
143
+ {
144
+ "data": [
145
+ {
146
+ "id": "5404329",
147
+ "type": "article",
148
+ "attributes": {
149
+ "author": "Canan Ercan",
150
+ "copies": 10000,
151
+ "publisher": "Webster & Canan Publishers",
152
+ "price": "700"
153
+ }
154
+ }
155
+ ],
156
+ "links": {
157
+ "first": "http://127.0.0.1:3000/api/v1/articles",
158
+ "prev": "http://127.0.0.1:3000/api/v1/articles?page[number]=349",
159
+ "self": "http://127.0.0.1:3000/api/v1/articles?page[number]=350",
160
+ "next": "http://127.0.0.1:3000/api/v1/articles?page[number]=351",
161
+ "last": "http://127.0.0.1:3000/api/v1/articles?page[number]=352"
162
+ }
163
+ }
164
+ ```
165
+
166
+
85
167
  ## Development
86
168
 
87
169
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -30,17 +30,17 @@ Gem::Specification.new do |spec|
30
30
  # that have been added into git.
31
31
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
32
32
  `git ls-files -z`.split("\x0").reject do |f|
33
- f.match(%r{^(test|spec|features)/})
33
+ f.match(%r{^(test|spec|features|Gemfile\.lock)/?})
34
34
  end
35
35
  end
36
36
  spec.bindir = 'exe'
37
37
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
38
38
  spec.require_paths = ['lib']
39
39
 
40
- spec.add_dependency 'dry-struct', '~>1.3.0'
41
- spec.add_dependency 'pagy', '~>3.8.3'
40
+ spec.add_dependency 'dry-struct', '~>1'
41
+ spec.add_dependency 'pagy', '~> 6'
42
42
  spec.add_dependency 'rack'
43
- spec.add_dependency 'addressable', '~> 2.3', '>= 2.3.7'
43
+ spec.add_dependency 'addressable', '~> 2'
44
44
 
45
45
  spec.add_development_dependency 'simplecov'
46
46
  spec.add_development_dependency 'simplecov-cobertura'
@@ -19,7 +19,7 @@ module JSOM
19
19
  attr_reader :page
20
20
 
21
21
  def pagy_custom(collection, page:)
22
- pagy = Pagy.new(count: collection.count, page: page.number, items: page.size)
22
+ pagy = Pagy.new(count: collection.size, page: page.number, items: page.size)
23
23
  paginated =
24
24
  if collection.is_a?(Array)
25
25
  collection[pagy.offset, pagy.items]
@@ -18,4 +18,4 @@ require 'pagy/extras/array'
18
18
  # See https://ddnexus.github.io/pagy/extras/overflow
19
19
  require 'pagy/extras/overflow'
20
20
 
21
- Pagy::VARS[:overflow] = :empty_page
21
+ Pagy::DEFAULT[:overflow] = :empty_page
@@ -2,6 +2,6 @@
2
2
 
3
3
  module JSOM
4
4
  module Pagination
5
- VERSION = '0.1.3'
5
+ VERSION = '1.0.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsom-pagination
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Wilgosz
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-20 00:00:00.000000000 Z
11
+ date: 2023-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-struct
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.3.0
19
+ version: '1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.3.0
26
+ version: '1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pagy
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 3.8.3
33
+ version: '6'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 3.8.3
40
+ version: '6'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rack
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,20 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '2.3'
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- version: 2.3.7
61
+ version: '2'
65
62
  type: :runtime
66
63
  prerelease: false
67
64
  version_requirements: !ruby/object:Gem::Requirement
68
65
  requirements:
69
66
  - - "~>"
70
67
  - !ruby/object:Gem::Version
71
- version: '2.3'
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: 2.3.7
68
+ version: '2'
75
69
  - !ruby/object:Gem::Dependency
76
70
  name: simplecov
77
71
  requirement: !ruby/object:Gem::Requirement
@@ -113,13 +107,13 @@ files:
113
107
  - ".github/workflows/gem-test.yml"
114
108
  - ".gitignore"
115
109
  - ".rspec"
110
+ - ".rubocop.disabled.yml"
116
111
  - ".rubocop.yml"
117
112
  - ".ruby-gemset"
118
113
  - ".ruby-version"
119
114
  - ".travis.yml"
120
115
  - CODE_OF_CONDUCT.md
121
116
  - Gemfile
122
- - Gemfile.lock
123
117
  - LICENSE.txt
124
118
  - README.md
125
119
  - Rakefile
@@ -143,7 +137,7 @@ metadata:
143
137
  homepage_uri: https://github.com/useo-pl/jsom-pagination
144
138
  source_code_uri: https://github.com/useo-pl/jsom-pagination
145
139
  changelog_uri: https://github.com/useo-pl/jsom-pagination/releases
146
- post_install_message:
140
+ post_install_message:
147
141
  rdoc_options: []
148
142
  require_paths:
149
143
  - lib
@@ -158,8 +152,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
152
  - !ruby/object:Gem::Version
159
153
  version: '0'
160
154
  requirements: []
161
- rubygems_version: 3.1.4
162
- signing_key:
155
+ rubygems_version: 3.4.10
156
+ signing_key:
163
157
  specification_version: 4
164
158
  summary: A pagination support for JSON:API based web applications.
165
159
  test_files: []
data/Gemfile.lock DELETED
@@ -1,78 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- jsom-pagination (0.1.3)
5
- addressable (~> 2.3, >= 2.3.7)
6
- dry-struct (~> 1.3.0)
7
- pagy (~> 3.8.3)
8
- rack
9
-
10
- GEM
11
- remote: https://rubygems.org/
12
- specs:
13
- addressable (2.7.0)
14
- public_suffix (>= 2.0.2, < 5.0)
15
- concurrent-ruby (1.1.8)
16
- diff-lcs (1.4.4)
17
- docile (1.3.2)
18
- dry-configurable (0.12.1)
19
- concurrent-ruby (~> 1.0)
20
- dry-core (~> 0.5, >= 0.5.0)
21
- dry-container (0.7.2)
22
- concurrent-ruby (~> 1.0)
23
- dry-configurable (~> 0.1, >= 0.1.3)
24
- dry-core (0.5.0)
25
- concurrent-ruby (~> 1.0)
26
- dry-equalizer (0.3.0)
27
- dry-inflector (0.2.0)
28
- dry-logic (1.2.0)
29
- concurrent-ruby (~> 1.0)
30
- dry-core (~> 0.5, >= 0.5)
31
- dry-struct (1.3.0)
32
- dry-core (~> 0.4, >= 0.4.4)
33
- dry-equalizer (~> 0.3)
34
- dry-types (~> 1.3)
35
- ice_nine (~> 0.11)
36
- dry-types (1.5.1)
37
- concurrent-ruby (~> 1.0)
38
- dry-container (~> 0.3)
39
- dry-core (~> 0.5, >= 0.5)
40
- dry-inflector (~> 0.1, >= 0.1.2)
41
- dry-logic (~> 1.0, >= 1.0.2)
42
- ice_nine (0.11.2)
43
- pagy (3.8.3)
44
- public_suffix (4.0.6)
45
- rack (2.2.3)
46
- rake (12.3.3)
47
- rspec (3.9.0)
48
- rspec-core (~> 3.9.0)
49
- rspec-expectations (~> 3.9.0)
50
- rspec-mocks (~> 3.9.0)
51
- rspec-core (3.9.2)
52
- rspec-support (~> 3.9.3)
53
- rspec-expectations (3.9.2)
54
- diff-lcs (>= 1.2.0, < 2.0)
55
- rspec-support (~> 3.9.0)
56
- rspec-mocks (3.9.1)
57
- diff-lcs (>= 1.2.0, < 2.0)
58
- rspec-support (~> 3.9.0)
59
- rspec-support (3.9.3)
60
- simplecov (0.19.0)
61
- docile (~> 1.1)
62
- simplecov-html (~> 0.11)
63
- simplecov-cobertura (1.4.0)
64
- simplecov (~> 0.8)
65
- simplecov-html (0.12.2)
66
-
67
- PLATFORMS
68
- ruby
69
-
70
- DEPENDENCIES
71
- jsom-pagination!
72
- rake (~> 12.0)
73
- rspec (~> 3.0)
74
- simplecov
75
- simplecov-cobertura
76
-
77
- BUNDLED WITH
78
- 2.1.4