paginator 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/paginator.rb +7 -2
  2. data/test/test_paginator.rb +16 -0
  3. metadata +1 -1
data/lib/paginator.rb CHANGED
@@ -2,7 +2,7 @@ require 'forwardable'
2
2
 
3
3
  class Paginator
4
4
 
5
- VERSION = '1.0.1'
5
+ VERSION = '1.0.2'
6
6
 
7
7
  class ArgumentError < ::ArgumentError; end
8
8
  class MissingCountError < ArgumentError; end
@@ -52,7 +52,12 @@ class Paginator
52
52
  # Retrieve page object by number
53
53
  def page(number)
54
54
  number = (n = number.to_i) > 0 ? n : 1
55
- Page.new(self, number, lambda{ @select.call((number - 1) * @per_page, @per_page) })
55
+ Page.new(self, number, lambda {
56
+ offset = (number - 1) * @per_page
57
+ args = [offset]
58
+ args << @per_page if @select.arity == 2
59
+ @select.call(*args)
60
+ })
56
61
  end
57
62
 
58
63
  # Page object
@@ -72,5 +72,21 @@ class PaginatorTest < Test::Unit::TestCase
72
72
  def test_number_of_pages
73
73
  assert_equal 5, @pager.number_of_pages
74
74
  end
75
+
76
+ def test_passing_block_to_initializer_with_arity_of_two_yields_per_page
77
+ pager = Paginator.new(20,2) do |offset,per_page|
78
+ assert_equal 2, per_page
79
+ end
80
+ pager.page(1).items
81
+ end
82
+
83
+ def test_passing_block_to_initializer_with_arity_of_one_does_not_yield_per_page
84
+ pager = Paginator.new(20,2) do |offset|
85
+ assert_equal 0, offset
86
+ end
87
+ pager.page(1).items
88
+ end
89
+
90
+
75
91
 
76
92
  end
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: paginator
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.1
6
+ version: 1.0.2
7
7
  date: 2006-10-24 00:00:00 -06:00
8
8
  summary: A generic paginator object for use in any Ruby program
9
9
  require_paths: