pagy 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pagy.rb +7 -7
  3. data/lib/pagy/backend.rb +6 -0
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a38bfeb3b81ab4359c9205b9eccd3af61b7413e6b2daa6aff42bd5ad0e13532
4
- data.tar.gz: d9cd8d3eccf9880895ed9293895a2eff313a8ae996f21f01781e7a718788aca5
3
+ metadata.gz: 4eb355e2e788692b281d40f9ef2d101eef85485ca76793194d53cd5f5a5b2d18
4
+ data.tar.gz: 6b3090fa7074a6b3ad109c6cf2d1bf7e92ab168818dc68aeb2dd08a5dbaf8f2e
5
5
  SHA512:
6
- metadata.gz: 8617020e93c6128ebb3ca5e9c4fd4a02540220c71addd1f257f39e48c486780e9f245a4b29c2b059c055ddc07207feb42be02ddf73ea1d33a11ac877909ef20b
7
- data.tar.gz: 7c69e723095bbea0c267c82cc6efa5c1dc11763668a8929f754fe6cf3b8b3e1265d2058d433b20776b7b78aef1dd32b1e29c9ab348607f23c4dd5cec752779f8
6
+ metadata.gz: c114e92d07dac9f3a47efc6c754d8b3ca8f7dfde8e46f7c04bbb35dd76e99879e52cf565d889645b841d363380db3c7c2bd15a571aaabc65675af1bb0ab738a6
7
+ data.tar.gz: 8ab8eac80d11c27af0b69d7fa32be4d3e8968981b993b19c3cfd2048ca9ce2632c640c366f25a8f40d377311ab07cee1293b6fcf1d0436a1ff0e3aa764f35521
data/lib/pagy.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'pathname'
4
4
 
5
- class Pagy ; VERSION = '0.7.0'
5
+ class Pagy ; VERSION = '0.7.1'
6
6
 
7
7
  autoload :Backend, 'pagy/backend'
8
8
  autoload :Frontend, 'pagy/frontend'
@@ -22,15 +22,15 @@ class Pagy ; VERSION = '0.7.0'
22
22
 
23
23
  # merge and validate the options, do some simple aritmetic and set the instance variables
24
24
  def initialize(vars)
25
- @vars = VARS.merge(vars.delete_if{|k,v| v.nil? or v == '' }) # default vars + cleaned instance vars
25
+ @vars = VARS.merge(vars.delete_if{|k,v| v.nil? || v == '' }) # default vars + cleaned instance vars
26
26
  { count:0, items:1, outset:0, page:1 }.each do |k,min| # validate core variables
27
- (@vars[k] && @vars[k].to_i >= min) or raise(ArgumentError, "expected :#{k} >= #{min}; got #{@vars[k].inspect}")
28
- instance_variable_set(:"@#{k}", @vars.delete(k).to_i) # set instance variables
27
+ (@vars[k] && instance_variable_set(:"@#{k}", @vars.delete(k).to_i) >= min) \
28
+ or raise(ArgumentError, "expected :#{k} >= #{min}; got #{instance_variable_get(:"@#{k}").inspect}")
29
29
  end
30
30
  @pages = @last = [(@count.to_f / @items).ceil, 1].max # cardinal and ordinal meanings
31
- (1..@last).cover?(@page) || raise(OutOfRangeError, "expected :page in 1..#{@last}; got #{@page.inspect}")
31
+ @page >= 1 && @page <= @last or raise(OutOfRangeError, "expected :page in 1..#{@last}; got #{@page.inspect}")
32
32
  @offset = @items * (@page - 1) + @outset # pagination offset + outset (initial offset)
33
- @items = @count % @items if @page == @last # adjust items for last page
33
+ @items = @count - ((@pages-1) * @items) if @page == @last # adjust items for last page
34
34
  @from = @count == 0 ? 0 : @offset+1 - @outset # page begins from item
35
35
  @to = @offset + @items - @outset # page ends to item
36
36
  @prev = (@page-1 unless @page == 1) # nil if no prev page
@@ -39,7 +39,7 @@ class Pagy ; VERSION = '0.7.0'
39
39
 
40
40
  # return the array of page numbers and :gap items e.g. [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
41
41
  def series(size=@vars[:size])
42
- (0..3).each{|i| (size[i]>=0 rescue nil) or raise(ArgumentError, "expected 4 items >= 0 in :size; got #{size.inspect}")}
42
+ 4.times{|i| (size[i]>=0 rescue nil) or raise(ArgumentError, "expected 4 items >= 0 in :size; got #{size.inspect}")}
43
43
  series = []
44
44
  [*0..size[0], *@page-size[1]..@page+size[2], *@last-size[3]+1..@last+1].sort!.each_cons(2) do |a, b|
45
45
  if a<0 || a==b || a>@last # skip out of range and duplicates
data/lib/pagy/backend.rb CHANGED
@@ -1,6 +1,12 @@
1
1
  # See Pagy::Backend API documentation: https://ddnexus.github.io/pagy/api/backend
2
2
 
3
3
  class Pagy
4
+ # Defines a few generic methods to paginate a ORM collection out of the box,
5
+ # or any collection by overriding pagy_get_items in your controller
6
+
7
+ # See also the pagy-extras gem if you need specialized methods to paginate
8
+ # Arrays, ORM, and other TBD collections
9
+
4
10
  module Backend ; private # the whole module is private so no problem with including it in a controller
5
11
 
6
12
  # return pagy object and items
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Domizio Demichelis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-21 00:00:00.000000000 Z
11
+ date: 2018-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler