next-pageable 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9f88eff8dad2504dd32c9a49afc24c19448da58ced5b120dd360f97e9d9710d
4
- data.tar.gz: 391ee2340288123774b646ed0001a11004c3e12ddf174462967a3a7e699d1ee1
3
+ metadata.gz: 5abdd23f398d5f529f959da4793c30db99807474476a51f56ca692068105f188
4
+ data.tar.gz: f525d4493a6f6aee5d27a530f4ec51510084effe7075d7bc17ac18c23b6f3b5b
5
5
  SHA512:
6
- metadata.gz: 6815d4b264c273e91642237acd7eaea2613a4075f2282a7574ec48215c147f131721f6519a7afd7c1f4f65e0de2f234526cf8ee87385f32845266c9680dcfd45
7
- data.tar.gz: df93a85fad5b596b143f27bcaabf32d133c6dd6ddc3cf9e59adc495c8570bf7e182be39e3af2f2317e9af789f28d07bdc3fc28527ca657ec78e627be39a42f1e
6
+ metadata.gz: ead4b6ee1a3abacfb9a9f5a0cebabcf54e18bcb8f7d1336ee59a47fc08abf45dd4122248d1e13543f27d26df2f3ae7dd1d38725379e63eca81efe1a75dd669dd
7
+ data.tar.gz: 40dad7991b5840033976cbd1b40e134664439a2254e5fe3cdd88596b787bdacba54052c846b676a92881184f7eda3df379abd38535827873f3fc29cdd6ef0588
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- next-pageable (0.1.1)
4
+ next-pageable (0.1.3)
5
5
  activesupport
6
6
 
7
7
  GEM
@@ -50,6 +50,7 @@ GEM
50
50
 
51
51
  PLATFORMS
52
52
  x86_64-darwin-21
53
+ x86_64-linux
53
54
 
54
55
  DEPENDENCIES
55
56
  minitest (~> 5.0)
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # NextPageable
2
2
 
3
- An ActiveRecord concern for basic paging support of ActiveRecord relations.
3
+ A minimalstic ActiveRecord concern for basic paging support of ActiveRecord relations avoiding extra count queries where not needed.
4
+
5
+ This gem is the perfect companion for [turbo-scroll](https://github.com/allcrux/turbo-scroll).
6
+
7
+ [![Ruby](https://github.com/allcrux/next-pageable/actions/workflows/main.yml/badge.svg)](https://github.com/allcrux/next-pageable/actions/workflows/main.yml)
4
8
 
5
9
  ## Installation
6
10
 
@@ -16,17 +20,16 @@ If bundler is not being used to manage dependencies, install the gem by executin
16
20
 
17
21
  To make your ActiveRecord relations pageable, inlude NextPageable on the models that you want to enrich.
18
22
 
19
- ```
23
+ ```rb
20
24
  class Article < ActiveRecord::Base
21
25
  include NextPageable
22
26
  ...
23
27
  end
24
28
  ```
25
29
 
26
- Alternatively, you can include NextPageable directly on your ApplicationRecord if you want it to be available to all
27
- of your models
30
+ Alternatively, you can include NextPageable directly on your ApplicationRecord if you want it to be available to all of your models.
28
31
 
29
- ```
32
+ ```rb
30
33
  class ApplicationRecord < ActiveRecord::Base
31
34
  include NextPageable
32
35
  ...
@@ -36,28 +39,28 @@ end
36
39
  For models that are enriched one extra class method `page` becomes available.
37
40
  It can be chained onto existing scope methods but should be the last method in the chain.
38
41
 
39
- ```
42
+ ```rb
40
43
  page = Article.all.page(0) # returns the 1st page for all articles
41
44
  page = Article.in_stock.page(3) # returns the 4th page for articles currently in stock
42
45
  ```
43
46
 
44
- Default pagesize is 15 but it can be passed as an extra parameter
47
+ Default pagesize is 15 but it can be passed as an extra parameter.
45
48
 
46
- ```
49
+ ```rb
47
50
  page = Article.all.page(1, pagesize: 50) # returns the 2nd page for all articles with a pagesize of 50
48
51
  ```
49
52
 
50
- You can directly iterate over the records on the page object:
53
+ You can directly iterate over the records on the page object.
51
54
 
52
- ```
55
+ ```rb
53
56
  page.each do |article|
54
57
  puts article
55
58
  end
56
59
  ```
57
60
 
58
- A page object also knows if there is a next page available and what the page value is
61
+ A page object also knows if there is a next page available and what the page value is.
59
62
 
60
- ```
63
+ ```rb
61
64
  page.next_page? # true
62
65
  page.next_page_index # 4
63
66
  ```
@@ -70,8 +73,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
70
73
 
71
74
  ## Contributing
72
75
 
73
- Bug reports and pull requests are welcome on GitHub at https://github.com/allcrux/next_pageable.
74
- This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/next_pageable/blob/main/CODE_OF_CONDUCT.md).
76
+ Bug reports and pull requests are welcome on GitHub at https://github.com/allcrux/next-pageable.
77
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/allcrux/next-pageable/blob/main/CODE_OF_CONDUCT.md).
75
78
 
76
79
  ## License
77
80
 
@@ -79,4 +82,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
79
82
 
80
83
  ## Code of Conduct
81
84
 
82
- Everyone interacting in the NextPageable project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/next_pageable/blob/main/CODE_OF_CONDUCT.md).
85
+ Everyone interacting in the NextPageable project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/allcrux/next-pageable/blob/main/CODE_OF_CONDUCT.md).
@@ -1,4 +1,4 @@
1
- require 'active_support/core_ext/module/delegation'
1
+ require "active_support/core_ext/module/delegation"
2
2
 
3
3
  module NextPageable
4
4
  class Page
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NextPageable
4
- VERSION = "0.1.3"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/next-pageable.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
- require 'active_support/concern'
2
+
3
+ require "active_support/concern"
3
4
 
4
5
  require_relative "next-pageable/version"
5
6
  require_relative "next-pageable/page"
@@ -8,18 +9,18 @@ module NextPageable
8
9
  extend ActiveSupport::Concern
9
10
 
10
11
  class_methods do
11
- def page(page, pagesize: 15)
12
+ def paginate(page, pagesize: 15)
12
13
  collection =
13
- self
14
- .limit(pagesize+1)
15
- .offset(page.to_i*pagesize)
14
+
15
+ limit(pagesize + 1)
16
+ .offset(page.to_i * pagesize)
16
17
 
17
18
  if collection.length > pagesize
18
- next_page_index = page.to_i+1
19
+ next_page_index = page.to_i + 1
19
20
  collection = collection[0...-1]
20
21
  end
21
22
 
22
- return Page.new(collection: collection, next_page_index: next_page_index)
23
+ Page.new(collection: collection, next_page_index: next_page_index)
23
24
  end
24
25
  end
25
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: next-pageable
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
  - Koen handekyn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-05 00:00:00.000000000 Z
11
+ date: 2022-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -42,16 +42,15 @@ files:
42
42
  - lib/next-pageable.rb
43
43
  - lib/next-pageable/page.rb
44
44
  - lib/next-pageable/version.rb
45
- - next-pageable.gemspec
46
45
  - sig/next-pageable.rbs
47
- homepage: https://github.com/allcrux/next_pageable
46
+ homepage: https://github.com/allcrux/next-pageable
48
47
  licenses:
49
48
  - MIT
50
49
  metadata:
51
50
  allowed_push_host: https://rubygems.org
52
- homepage_uri: https://github.com/allcrux/next_pageable
53
- source_code_uri: https://github.com/allcrux/next_pageable
54
- changelog_uri: https://github.com/allcrux/next_pageable/blob/main/CHANGELOG.md
51
+ homepage_uri: https://github.com/allcrux/next-pageable
52
+ source_code_uri: https://github.com/allcrux/next-pageable
53
+ changelog_uri: https://github.com/allcrux/next-pageable/blob/main/CHANGELOG.md
55
54
  post_install_message:
56
55
  rdoc_options: []
57
56
  require_paths:
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/next-pageable/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "next-pageable"
7
- spec.version = NextPageable::VERSION
8
- spec.authors = ["Koen handekyn"]
9
- spec.email = ["koen@handekyn.com"]
10
-
11
- spec.summary = "Simple paging extension for ActiveRecord::Model."
12
- spec.description = "An ActiveModel concern for basic paging without an extra count query."
13
- spec.homepage = "https://github.com/allcrux/next_pageable"
14
- spec.license = "MIT"
15
- spec.required_ruby_version = ">= 3.0.0"
16
-
17
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
-
19
- spec.metadata["homepage_uri"] = spec.homepage
20
- spec.metadata["source_code_uri"] = "https://github.com/allcrux/next_pageable"
21
- spec.metadata["changelog_uri"] = "https://github.com/allcrux/next_pageable/blob/main/CHANGELOG.md"
22
-
23
- # Specify which files should be added to the gem when it is released.
24
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
- spec.files = Dir.chdir(__dir__) do
26
- `git ls-files -z`.split("\x0").reject do |f|
27
- (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
28
- end
29
- end
30
- spec.bindir = "exe"
31
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
- spec.require_paths = ["lib"]
33
-
34
- spec.add_dependency "activesupport"
35
-
36
- # For more information and examples about making a new gem, check out our
37
- # guide at: https://bundler.io/guides/creating_gem.html
38
- end