paginator 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/lib/paginator.rb +10 -2
- data/test/test_paginator.rb +15 -0
- metadata +2 -2
data/History.txt
CHANGED
data/lib/paginator.rb
CHANGED
@@ -2,7 +2,7 @@ require 'forwardable'
|
|
2
2
|
|
3
3
|
class Paginator
|
4
4
|
|
5
|
-
VERSION = '1.0.
|
5
|
+
VERSION = '1.0.6'
|
6
6
|
|
7
7
|
class ArgumentError < ::ArgumentError; end
|
8
8
|
class MissingCountError < ArgumentError; end
|
@@ -44,8 +44,15 @@ class Paginator
|
|
44
44
|
|
45
45
|
# Iterate through pages
|
46
46
|
def each
|
47
|
+
each_with_index do |item, index|
|
48
|
+
yield item
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Iterate through pages with indices
|
53
|
+
def each_with_index
|
47
54
|
1.upto(number_of_pages) do |number|
|
48
|
-
yield
|
55
|
+
yield(page(number), number - 1)
|
49
56
|
end
|
50
57
|
end
|
51
58
|
|
@@ -70,6 +77,7 @@ class Paginator
|
|
70
77
|
def_delegator :@pager, :first, :first
|
71
78
|
def_delegator :@pager, :last, :last
|
72
79
|
def_delegator :items, :each
|
80
|
+
def_delegator :items, :each_with_index
|
73
81
|
|
74
82
|
attr_reader :number, :pager
|
75
83
|
|
data/test/test_paginator.rb
CHANGED
@@ -69,6 +69,21 @@ class PaginatorTest < Test::Unit::TestCase
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
+
def test_each_with_index
|
73
|
+
page_offset = 0
|
74
|
+
@pager.each_with_index do |page, page_index|
|
75
|
+
assert page
|
76
|
+
assert_equal page_offset, page_index
|
77
|
+
item_offset = 0
|
78
|
+
page.each_with_index do |item, item_index|
|
79
|
+
assert item
|
80
|
+
assert_equal item_offset, item_index
|
81
|
+
item_offset += 1
|
82
|
+
end
|
83
|
+
page_offset += 1
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
72
87
|
def test_number_of_pages
|
73
88
|
assert_equal 5, @pager.number_of_pages
|
74
89
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ 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.
|
7
|
-
date: 2006-
|
6
|
+
version: 1.0.6
|
7
|
+
date: 2006-11-02 00:00:00 -07:00
|
8
8
|
summary: A generic paginator object for use in any Ruby program
|
9
9
|
require_paths:
|
10
10
|
- lib
|