paginator 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ == 1.0.6 / 2006-11-02
2
+
3
+ * Added each_with_index to Paginator and Page classes
4
+
1
5
  == 1.0.5 / 2006-10-27
2
6
 
3
7
  * Fix to Rakefile (addresses #6304)
@@ -2,7 +2,7 @@ require 'forwardable'
2
2
 
3
3
  class Paginator
4
4
 
5
- VERSION = '1.0.5'
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 page(number)
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
 
@@ -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.5
7
- date: 2006-10-27 00:00:00 -06:00
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