next-pageable 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b9f88eff8dad2504dd32c9a49afc24c19448da58ced5b120dd360f97e9d9710d
4
+ data.tar.gz: 391ee2340288123774b646ed0001a11004c3e12ddf174462967a3a7e699d1ee1
5
+ SHA512:
6
+ metadata.gz: 6815d4b264c273e91642237acd7eaea2613a4075f2282a7574ec48215c147f131721f6519a7afd7c1f4f65e0de2f234526cf8ee87385f32845266c9680dcfd45
7
+ data.tar.gz: df93a85fad5b596b143f27bcaabf32d133c6dd6ddc3cf9e59adc495c8570bf7e182be39e3af2f2317e9af789f28d07bdc3fc28527ca657ec78e627be39a42f1e
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
3
+ ruby_version: 2.6
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-08-04
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at koen@handekyn.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in next-pageable.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
11
+
12
+ gem "standard", "~> 1.3"
data/Gemfile.lock ADDED
@@ -0,0 +1,61 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ next-pageable (0.1.1)
5
+ activesupport
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (7.0.3.1)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 1.6, < 2)
13
+ minitest (>= 5.1)
14
+ tzinfo (~> 2.0)
15
+ ast (2.4.2)
16
+ concurrent-ruby (1.1.10)
17
+ i18n (1.12.0)
18
+ concurrent-ruby (~> 1.0)
19
+ json (2.6.2)
20
+ minitest (5.16.2)
21
+ parallel (1.22.1)
22
+ parser (3.1.2.0)
23
+ ast (~> 2.4.1)
24
+ rainbow (3.1.1)
25
+ rake (13.0.6)
26
+ regexp_parser (2.5.0)
27
+ rexml (3.2.5)
28
+ rubocop (1.32.0)
29
+ json (~> 2.3)
30
+ parallel (~> 1.10)
31
+ parser (>= 3.1.0.0)
32
+ rainbow (>= 2.2.2, < 4.0)
33
+ regexp_parser (>= 1.8, < 3.0)
34
+ rexml (>= 3.2.5, < 4.0)
35
+ rubocop-ast (>= 1.19.1, < 2.0)
36
+ ruby-progressbar (~> 1.7)
37
+ unicode-display_width (>= 1.4.0, < 3.0)
38
+ rubocop-ast (1.19.1)
39
+ parser (>= 3.1.1.0)
40
+ rubocop-performance (1.14.3)
41
+ rubocop (>= 1.7.0, < 2.0)
42
+ rubocop-ast (>= 0.4.0)
43
+ ruby-progressbar (1.11.0)
44
+ standard (1.14.0)
45
+ rubocop (= 1.32.0)
46
+ rubocop-performance (= 1.14.3)
47
+ tzinfo (2.0.5)
48
+ concurrent-ruby (~> 1.0)
49
+ unicode-display_width (2.2.0)
50
+
51
+ PLATFORMS
52
+ x86_64-darwin-21
53
+
54
+ DEPENDENCIES
55
+ minitest (~> 5.0)
56
+ next-pageable!
57
+ rake (~> 13.0)
58
+ standard (~> 1.3)
59
+
60
+ BUNDLED WITH
61
+ 2.3.15
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Allcrux
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # NextPageable
2
+
3
+ An ActiveRecord concern for basic paging support of ActiveRecord relations.
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ $ bundle add next-pageable
10
+
11
+ If bundler is not being used to manage dependencies, install the gem by executing:
12
+
13
+ $ gem install next-pageable
14
+
15
+ ## Usage
16
+
17
+ To make your ActiveRecord relations pageable, inlude NextPageable on the models that you want to enrich.
18
+
19
+ ```
20
+ class Article < ActiveRecord::Base
21
+ include NextPageable
22
+ ...
23
+ end
24
+ ```
25
+
26
+ Alternatively, you can include NextPageable directly on your ApplicationRecord if you want it to be available to all
27
+ of your models
28
+
29
+ ```
30
+ class ApplicationRecord < ActiveRecord::Base
31
+ include NextPageable
32
+ ...
33
+ end
34
+ ```
35
+
36
+ For models that are enriched one extra class method `page` becomes available.
37
+ It can be chained onto existing scope methods but should be the last method in the chain.
38
+
39
+ ```
40
+ page = Article.all.page(0) # returns the 1st page for all articles
41
+ page = Article.in_stock.page(3) # returns the 4th page for articles currently in stock
42
+ ```
43
+
44
+ Default pagesize is 15 but it can be passed as an extra parameter
45
+
46
+ ```
47
+ page = Article.all.page(1, pagesize: 50) # returns the 2nd page for all articles with a pagesize of 50
48
+ ```
49
+
50
+ You can directly iterate over the records on the page object:
51
+
52
+ ```
53
+ page.each do |article|
54
+ puts article
55
+ end
56
+ ```
57
+
58
+ A page object also knows if there is a next page available and what the page value is
59
+
60
+ ```
61
+ page.next_page? # true
62
+ page.next_page_index # 4
63
+ ```
64
+
65
+ ## Development
66
+
67
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
68
+
69
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
70
+
71
+ ## Contributing
72
+
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).
75
+
76
+ ## License
77
+
78
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
79
+
80
+ ## Code of Conduct
81
+
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).
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ require "standard/rake"
13
+
14
+ task default: %i[test standard]
@@ -0,0 +1,25 @@
1
+ require 'active_support/core_ext/module/delegation'
2
+
3
+ module NextPageable
4
+ class Page
5
+ include Enumerable
6
+
7
+ attr_reader :collection
8
+ attr_reader :next_page_index
9
+
10
+ def initialize(collection:, next_page_index:)
11
+ @collection = collection
12
+ @next_page_index = next_page_index
13
+ end
14
+
15
+ delegate :each, to: :collection
16
+ delegate :to_ary, to: :collection
17
+ delegate :to_a, to: :collection
18
+ delegate :size, to: :collection
19
+ delegate :length, to: :collection
20
+
21
+ def next_page?
22
+ next_page_index.present?
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NextPageable
4
+ VERSION = "0.1.3"
5
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ require 'active_support/concern'
3
+
4
+ require_relative "next-pageable/version"
5
+ require_relative "next-pageable/page"
6
+
7
+ module NextPageable
8
+ extend ActiveSupport::Concern
9
+
10
+ class_methods do
11
+ def page(page, pagesize: 15)
12
+ collection =
13
+ self
14
+ .limit(pagesize+1)
15
+ .offset(page.to_i*pagesize)
16
+
17
+ if collection.length > pagesize
18
+ next_page_index = page.to_i+1
19
+ collection = collection[0...-1]
20
+ end
21
+
22
+ return Page.new(collection: collection, next_page_index: next_page_index)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,38 @@
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
@@ -0,0 +1,4 @@
1
+ module NextPageable
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: next-pageable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Koen handekyn
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-08-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: An ActiveModel concern for basic paging without an extra count query.
28
+ email:
29
+ - koen@handekyn.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".standard.yml"
35
+ - CHANGELOG.md
36
+ - CODE_OF_CONDUCT.md
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - LICENSE
40
+ - README.md
41
+ - Rakefile
42
+ - lib/next-pageable.rb
43
+ - lib/next-pageable/page.rb
44
+ - lib/next-pageable/version.rb
45
+ - next-pageable.gemspec
46
+ - sig/next-pageable.rbs
47
+ homepage: https://github.com/allcrux/next_pageable
48
+ licenses:
49
+ - MIT
50
+ metadata:
51
+ 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
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 3.0.0
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.3.7
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Simple paging extension for ActiveRecord::Model.
74
+ test_files: []