jsom-pagination 0.1.3 → 0.2.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: 27b6274de4e4cdc7a40b3b729be4b541648402b89a5d1226339df372c6d5926f
4
+ data.tar.gz: c19be09cfa6e72aae8cd725d102999f5b40fafd56d2973405d4c9b40615342bb
5
5
  SHA512:
6
- metadata.gz: 870e1557784ce98ef46bc8f7d7e86b84ebc3bc7ad04d74de49963160ceb10046ef21b4ce60f9d7573582ed2282819e1246304f0cdbe7b5e73c79649365bf3dbb
7
- data.tar.gz: 4c08dcc05cf729b7c53a760ae7e1e28aabe25690bc671858ec54502034d9c96f3cbbcaf7a7321cc7bb328937a4aeffc4fdb3f0b74b367b65b6f936c681dcd122
6
+ metadata.gz: cb5be3723a23a0c13769a65aa9f0bdc73106348e14c3a970823435641764a2748837f0e8cb282830f652dc7dcc5ddb35c4f0c3aaf3d9e3408f9b52082d4340ad
7
+ data.tar.gz: e1a3c291ca065a5fad11ae3705d1a60117ca36d82cfe4803f2f16d52d6f276396bc67860e56793f46a75be7527b488ecfa54733d25f1802829099f8a9e97eece
@@ -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: ['2.7', '3.0']
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@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
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: ['2.7', '3.0']
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@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
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/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,15 +30,15 @@ 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.3'
41
+ spec.add_dependency 'pagy', '~>4.0'
42
42
  spec.add_dependency 'rack'
43
43
  spec.add_dependency 'addressable', '~> 2.3', '>= 2.3.7'
44
44
 
@@ -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]
@@ -2,6 +2,6 @@
2
2
 
3
3
  module JSOM
4
4
  module Pagination
5
- VERSION = '0.1.3'
5
+ VERSION = '0.2.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: 0.2.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: 2022-04-25 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.3'
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.3'
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: '4.0'
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: '4.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rack
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -113,13 +113,13 @@ files:
113
113
  - ".github/workflows/gem-test.yml"
114
114
  - ".gitignore"
115
115
  - ".rspec"
116
+ - ".rubocop.disabled.yml"
116
117
  - ".rubocop.yml"
117
118
  - ".ruby-gemset"
118
119
  - ".ruby-version"
119
120
  - ".travis.yml"
120
121
  - CODE_OF_CONDUCT.md
121
122
  - Gemfile
122
- - Gemfile.lock
123
123
  - LICENSE.txt
124
124
  - README.md
125
125
  - Rakefile
@@ -143,7 +143,7 @@ metadata:
143
143
  homepage_uri: https://github.com/useo-pl/jsom-pagination
144
144
  source_code_uri: https://github.com/useo-pl/jsom-pagination
145
145
  changelog_uri: https://github.com/useo-pl/jsom-pagination/releases
146
- post_install_message:
146
+ post_install_message:
147
147
  rdoc_options: []
148
148
  require_paths:
149
149
  - lib
@@ -158,8 +158,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  - !ruby/object:Gem::Version
159
159
  version: '0'
160
160
  requirements: []
161
- rubygems_version: 3.1.4
162
- signing_key:
161
+ rubygems_version: 3.2.3
162
+ signing_key:
163
163
  specification_version: 4
164
164
  summary: A pagination support for JSON:API based web applications.
165
165
  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