smart_paginate 0.1.3 → 0.2.3

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
- SHA1:
3
- metadata.gz: 9243f8c82e00d6a698b211f5faf99b157a2043d1
4
- data.tar.gz: 86f6b75eecbe883132662b2a166b73a618e51e2e
2
+ SHA256:
3
+ metadata.gz: 9d8041e61e6e5d83f41479eececc725653fa31d5a41b0f722dda1e35370849b5
4
+ data.tar.gz: 92008b68acb9accac3cf83a8b62c90029daa178a38d6e00e2998dd32c92ae873
5
5
  SHA512:
6
- metadata.gz: f5835bb0bd176338657b610a09629498024f0d54c5e21ab7812d26c661960466cd3a5af8ece7ea6e7da37d5aba32a97f8332a5891fe1eedba8c66d8d37fdd5b2
7
- data.tar.gz: dcf6088fd14c62731730bf5420b0581ab7869202f84bb99a7a79c0deda8d2c7319f604e662d87f0a6cde862dc47dc93b849405a72310b5e9878633e12971b780
6
+ metadata.gz: 91af3d19e02da4941031ed8e8d0c89997d5ec6492b490f17b820f398bf515542dd70210b27393e0104c12b381a26e33e0e9c026d7d5e5702e6ac4f2146f4b62b
7
+ data.tar.gz: 59c94c291a8a4837f00df962a34db5b53252ad64b031cea8c3ec5c04410ace086f945af73945fd1b0b546aba2954c92797f44e38015af237a654885b30fb1212
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # SmartPaginate
2
2
 
3
- [![Build Status](https://travis-ci.org/ppostma/smart_paginate.svg?branch=master)](https://travis-ci.org/ppostma/smart_paginate)
3
+ [![Gem Version](https://badge.fury.io/rb/smart_paginate.svg)](https://badge.fury.io/rb/smart_paginate)
4
+ [![Build Status](https://github.com/ppostma/smart_paginate/actions/workflows/test.yml/badge.svg)](https://github.com/ppostma/smart_paginate/actions)
5
+ [![Code Climate](https://codeclimate.com/github/ppostma/smart_paginate/badges/gpa.svg)](https://codeclimate.com/github/ppostma/smart_paginate)
4
6
 
5
7
  Simple, smart and clean pagination extension for Active Record and plain Ruby Arrays:
6
8
 
@@ -74,8 +76,6 @@ module PaginateHelper
74
76
  def paginate(collection, options = {})
75
77
  content_tag(:div, class: "pagination") do
76
78
  if collection.present?
77
- options = options.merge(params)
78
-
79
79
  concat link_to("Previous", url_for(options.merge(per_page: collection.per_page, page: collection.previous_page)), class: "previous_page") if collection.previous_page?
80
80
  concat link_to("Next", url_for(options.merge(per_page: collection.per_page, page: collection.next_page)), class: "next_page") if collection.next_page?
81
81
  end
@@ -84,6 +84,13 @@ module PaginateHelper
84
84
  end
85
85
  ```
86
86
 
87
+ Which you can then use in the view like this:
88
+
89
+ ```ruby
90
+ <%= paginate(@objects, params.permit) %>
91
+ ```
92
+
93
+ Make sure you whitelist the allowed parameters!
87
94
 
88
95
  ## Contributing
89
96
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "smart_paginate/paginate"
2
4
  require "active_support/concern"
3
5
  require "active_record"
@@ -66,7 +68,7 @@ module SmartPaginate
66
68
  end
67
69
 
68
70
  def total_pages
69
- (total_entries / per_page.to_f).ceil
71
+ total_entries.positive? ? (total_entries / per_page.to_f).ceil : 1
70
72
  end
71
73
 
72
74
  def total_entries
@@ -74,7 +76,7 @@ module SmartPaginate
74
76
  load # make sure we have determined the number of fetched records
75
77
 
76
78
  # if we know that there are no more records, then we can calculate total_entries
77
- if @number_of_records <= per_page
79
+ if (current_page == 1 || @number_of_records.positive?) && @number_of_records <= per_page
78
80
  offset_value + @number_of_records
79
81
  else
80
82
  rel = except(:limit, :offset)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SmartPaginate
2
4
  class Paginate
3
5
  attr_reader :current_page, :per_page
@@ -15,7 +17,7 @@ module SmartPaginate
15
17
 
16
18
  def convert(value, default_value)
17
19
  value = value.to_i
18
- value > 0 ? value : default_value
20
+ value.positive? ? value : default_value
19
21
  end
20
22
  end
21
23
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "smart_paginate/paginate"
2
4
 
3
5
  module SmartPaginate
@@ -7,7 +9,13 @@ module SmartPaginate
7
9
  def paginate(options = {})
8
10
  page = SmartPaginate::Paginate.new(options.fetch(:page), options[:per_page])
9
11
 
10
- array = self.slice(page.offset, page.per_page)
12
+ if page.offset <= length
13
+ array = PaginatingArray.new(self.slice(page.offset, page.per_page))
14
+ else
15
+ # out of bounds, just create an empty array
16
+ array = PaginatingArray.new
17
+ end
18
+
11
19
  array.current_page = page.current_page
12
20
  array.per_page = page.per_page
13
21
  array.total_entries = length
@@ -31,7 +39,7 @@ module SmartPaginate
31
39
  end
32
40
 
33
41
  def total_pages
34
- (total_entries / per_page.to_f).ceil
42
+ total_entries.positive? ? (total_entries / per_page.to_f).ceil : 1
35
43
  end
36
44
  end
37
45
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SmartPaginate
2
- VERSION = "0.1.3"
4
+ VERSION = "0.2.3"
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "smart_paginate/active_record_extension"
2
4
  require "smart_paginate/paginating_array"
3
5
  require "smart_paginate/version"
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_paginate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Postma
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-06 00:00:00.000000000 Z
11
+ date: 2022-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.12'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.12'
27
27
  - !ruby/object:Gem::Dependency
@@ -30,54 +30,42 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '13.0'
34
34
  type: :development
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: '10.0'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 3.4.0
48
- - - ">="
49
- - !ruby/object:Gem::Version
50
- version: 3.4.0
47
+ version: 3.10.0
51
48
  type: :development
52
49
  prerelease: false
53
50
  version_requirements: !ruby/object:Gem::Requirement
54
51
  requirements:
55
52
  - - "~>"
56
53
  - !ruby/object:Gem::Version
57
- version: 3.4.0
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- version: 3.4.0
54
+ version: 3.10.0
61
55
  - !ruby/object:Gem::Dependency
62
- name: sqlite3
56
+ name: rubocop
63
57
  requirement: !ruby/object:Gem::Requirement
64
58
  requirements:
65
59
  - - "~>"
66
60
  - !ruby/object:Gem::Version
67
- version: '1.3'
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- version: 1.3.11
61
+ version: 0.81.0
71
62
  type: :development
72
63
  prerelease: false
73
64
  version_requirements: !ruby/object:Gem::Requirement
74
65
  requirements:
75
66
  - - "~>"
76
67
  - !ruby/object:Gem::Version
77
- version: '1.3'
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- version: 1.3.11
68
+ version: 0.81.0
81
69
  - !ruby/object:Gem::Dependency
82
70
  name: activerecord
83
71
  requirement: !ruby/object:Gem::Requirement
@@ -85,9 +73,6 @@ dependencies:
85
73
  - - ">="
86
74
  - !ruby/object:Gem::Version
87
75
  version: 4.0.0
88
- - - "<"
89
- - !ruby/object:Gem::Version
90
- version: '5.1'
91
76
  type: :runtime
92
77
  prerelease: false
93
78
  version_requirements: !ruby/object:Gem::Requirement
@@ -95,9 +80,6 @@ dependencies:
95
80
  - - ">="
96
81
  - !ruby/object:Gem::Version
97
82
  version: 4.0.0
98
- - - "<"
99
- - !ruby/object:Gem::Version
100
- version: '5.1'
101
83
  description: Simple, smart and clean pagination extension for Active Record and plain
102
84
  Ruby Arrays.
103
85
  email:
@@ -106,29 +88,19 @@ executables: []
106
88
  extensions: []
107
89
  extra_rdoc_files: []
108
90
  files:
109
- - ".gitignore"
110
- - ".rspec"
111
- - ".rubocop.yml"
112
- - ".travis.yml"
113
- - Gemfile
114
91
  - LICENSE.txt
115
92
  - README.md
116
- - Rakefile
117
- - gemfiles/Gemfile.active_record-4.0
118
- - gemfiles/Gemfile.active_record-4.1
119
- - gemfiles/Gemfile.active_record-4.2
120
- - gemfiles/Gemfile.active_record-5.0
121
93
  - lib/smart_paginate.rb
122
94
  - lib/smart_paginate/active_record_extension.rb
123
95
  - lib/smart_paginate/paginate.rb
124
96
  - lib/smart_paginate/paginating_array.rb
125
97
  - lib/smart_paginate/version.rb
126
- - smart_paginate.gemspec
127
98
  homepage: https://github.com/ppostma/smart_paginate
128
99
  licenses:
129
100
  - MIT
130
- metadata: {}
131
- post_install_message:
101
+ metadata:
102
+ rubygems_mfa_required: 'true'
103
+ post_install_message:
132
104
  rdoc_options: []
133
105
  require_paths:
134
106
  - lib
@@ -143,9 +115,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
115
  - !ruby/object:Gem::Version
144
116
  version: '0'
145
117
  requirements: []
146
- rubyforge_project:
147
- rubygems_version: 2.4.8
148
- signing_key:
118
+ rubygems_version: 3.3.7
119
+ signing_key:
149
120
  specification_version: 4
150
121
  summary: Simple, smart and clean pagination extension
151
122
  test_files: []
data/.gitignore DELETED
@@ -1,11 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- .ruby-version
11
- .ruby-gemset
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --format documentation
2
- --color
data/.rubocop.yml DELETED
@@ -1,29 +0,0 @@
1
- AllCops:
2
- TargetRubyVersion: 2.2
3
- DisplayCopNames: true
4
- DisplayStyleGuide: true
5
- Exclude:
6
- - 'gemfiles/vendor/**/*'
7
- - 'lib/smart_paginate/version.rb'
8
-
9
- Metrics/LineLength:
10
- Enabled: false
11
-
12
- Style/BlockComments:
13
- Exclude:
14
- - 'spec/**/*.rb'
15
-
16
- Style/Documentation:
17
- Enabled: false
18
-
19
- Style/GuardClause:
20
- Enabled: false
21
-
22
- Style/IfUnlessModifier:
23
- Enabled: false
24
-
25
- Style/RedundantSelf:
26
- Enabled: false
27
-
28
- Style/StringLiterals:
29
- Enabled: false
data/.travis.yml DELETED
@@ -1,11 +0,0 @@
1
- language: ruby
2
- sudo: false
3
- cache: bundler
4
- rvm:
5
- - 2.2.5
6
- - 2.3.1
7
- gemfile:
8
- - gemfiles/Gemfile.active_record-4.0
9
- - gemfiles/Gemfile.active_record-4.1
10
- - gemfiles/Gemfile.active_record-4.2
11
- - gemfiles/Gemfile.active_record-5.0
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in smart_paginate.gemspec
4
- gemspec
5
-
6
- gem 'rubocop', '~> 0.43.0', group: :test
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
- require "rubocop/rake_task"
4
-
5
- RSpec::Core::RakeTask.new(:spec)
6
- RuboCop::RakeTask.new(:rubocop)
7
-
8
- task default: [:spec, :rubocop]
@@ -1,8 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in smart_paginate.gemspec
4
- gemspec path: '..'
5
-
6
- gem 'activerecord', '~> 4.0.0'
7
-
8
- gem 'rubocop', '~> 0.43.0', group: :test
@@ -1,8 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in smart_paginate.gemspec
4
- gemspec path: '..'
5
-
6
- gem 'activerecord', '~> 4.1.0'
7
-
8
- gem 'rubocop', '~> 0.43.0', group: :test
@@ -1,8 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in smart_paginate.gemspec
4
- gemspec path: '..'
5
-
6
- gem 'activerecord', '~> 4.2.0'
7
-
8
- gem 'rubocop', '~> 0.43.0', group: :test
@@ -1,8 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in smart_paginate.gemspec
4
- gemspec path: '..'
5
-
6
- gem 'activerecord', '~> 5.0.0'
7
-
8
- gem 'rubocop', '~> 0.43.0', group: :test
@@ -1,28 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'smart_paginate/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "smart_paginate"
8
- spec.version = SmartPaginate::VERSION
9
- spec.authors = ["Peter Postma"]
10
- spec.email = ["peter.postma@gmail.com"]
11
-
12
- spec.summary = "Simple, smart and clean pagination extension"
13
- spec.description = "Simple, smart and clean pagination extension for Active Record and plain Ruby Arrays."
14
- spec.homepage = "https://github.com/ppostma/smart_paginate"
15
- spec.license = "MIT"
16
-
17
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = "exe"
19
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
21
-
22
- spec.add_development_dependency "bundler", "~> 1.12"
23
- spec.add_development_dependency "rake", "~> 10.0"
24
- spec.add_development_dependency "rspec", "~> 3.4.0", ">= 3.4.0"
25
- spec.add_development_dependency "sqlite3", "~> 1.3", ">= 1.3.11"
26
-
27
- spec.add_dependency "activerecord", ">= 4.0.0", "< 5.1"
28
- end