simply_paginate 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +0 -1
- data/.travis.yml +3 -8
- data/Gemfile +1 -0
- data/Gemfile.lock +35 -0
- data/Rakefile +3 -6
- data/lib/simply_paginate/page.rb +3 -3
- data/lib/simply_paginate/paginator.rb +5 -5
- data/lib/simply_paginate/version.rb +1 -1
- data/simply_paginate.gemspec +1 -1
- data/spec/page_spec.rb +79 -24
- data/spec/paginator_spec.rb +52 -53
- data/spec/spec_helper.rb +2 -13
- metadata +17 -25
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 39276d355bff6efc4caf226f0c12651ceb5f57cb
|
4
|
+
data.tar.gz: 74c736370477949887a729652a116d43ff0cf880
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 828ca2c53d150cd0e29e9da3aea11e573dd89e843a3d663ccaa2bfe3e4b7a9e24bb647f5a030ba50b5e7daa6899a9d63eeae4c6f3dc7887d09eaa07fd744d164
|
7
|
+
data.tar.gz: 61ded93564918688aecc72ca5d1243b02464bc536303f5e053459b6dd4355cfa341bc292b247b2641844a69bb2774ef1f1e3ee9dc77940cae7ad42bb6b1c3d79
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
simply_paginate (0.0.5)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.2.5)
|
10
|
+
rake (10.0.4)
|
11
|
+
rspec (3.5.0)
|
12
|
+
rspec-core (~> 3.5.0)
|
13
|
+
rspec-expectations (~> 3.5.0)
|
14
|
+
rspec-mocks (~> 3.5.0)
|
15
|
+
rspec-core (3.5.3)
|
16
|
+
rspec-support (~> 3.5.0)
|
17
|
+
rspec-expectations (3.5.0)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.5.0)
|
20
|
+
rspec-mocks (3.5.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.5.0)
|
23
|
+
rspec-support (3.5.0)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.3)
|
30
|
+
rake
|
31
|
+
rspec
|
32
|
+
simply_paginate!
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.12.5
|
data/Rakefile
CHANGED
@@ -1,10 +1,7 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
2
|
require 'rake/testtask'
|
3
|
+
require 'rspec/core/rake_task'
|
3
4
|
|
4
|
-
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
6
|
|
6
|
-
|
7
|
-
test.libs = ['lib', 'spec']
|
8
|
-
test.verbose = true
|
9
|
-
test.test_files = FileList['spec/*_spec.rb']
|
10
|
-
end
|
7
|
+
task :default => :spec
|
data/lib/simply_paginate/page.rb
CHANGED
@@ -8,8 +8,8 @@ module SimplyPaginate
|
|
8
8
|
@size = size
|
9
9
|
|
10
10
|
@move_page = lambda do |number|
|
11
|
-
new_index =
|
12
|
-
Page.new(new_index,
|
11
|
+
new_index = index + number
|
12
|
+
Page.new(new_index, collection, size) unless (new_index <= 0) || (new_index > (collection.count.to_f / size.to_f).ceil)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -29,7 +29,7 @@ module SimplyPaginate
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def ==(other)
|
32
|
-
(index == other.index) && (elements == other.elements)
|
32
|
+
(index == other.index) && (elements == other.elements)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -33,19 +33,19 @@ module SimplyPaginate
|
|
33
33
|
(@collection.count.to_f / @per_page.to_f).ceil
|
34
34
|
end
|
35
35
|
|
36
|
-
def [](
|
37
|
-
Page.new(
|
36
|
+
def [](index)
|
37
|
+
Page.new(index, @collection, @per_page) unless collection.empty? || index <= 0 || index > total_pages
|
38
38
|
end
|
39
39
|
|
40
40
|
## Iteration
|
41
41
|
|
42
42
|
def next!
|
43
|
-
raise NoMethodError.new("You need to start before iterating") unless
|
44
|
-
@current =
|
43
|
+
raise NoMethodError.new("You need to start before iterating") unless current
|
44
|
+
@current = current.next
|
45
45
|
end
|
46
46
|
|
47
47
|
def next?
|
48
|
-
|
48
|
+
current != nil
|
49
49
|
end
|
50
50
|
|
51
51
|
def start
|
data/simply_paginate.gemspec
CHANGED
data/spec/page_spec.rb
CHANGED
@@ -1,39 +1,94 @@
|
|
1
|
-
|
1
|
+
require_relative 'spec_helper'
|
2
2
|
|
3
3
|
include SimplyPaginate
|
4
4
|
|
5
5
|
describe Page do
|
6
|
-
|
6
|
+
context "when is empty" do
|
7
|
+
let(:page) { Page.new(0, []) }
|
8
|
+
subject { page }
|
7
9
|
|
8
|
-
|
10
|
+
describe "#elements" do
|
11
|
+
specify { expect(subject.elements).to be_nil }
|
12
|
+
end
|
9
13
|
|
10
|
-
|
14
|
+
describe "#next" do
|
15
|
+
specify { expect(subject.next).to be_nil }
|
16
|
+
end
|
11
17
|
|
12
|
-
|
18
|
+
describe "#previous" do
|
19
|
+
specify { expect(subject.previous).to be_nil }
|
20
|
+
end
|
13
21
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
22
|
+
describe "#==" do
|
23
|
+
subject { page == other_page }
|
24
|
+
let(:other_page) { double }
|
18
25
|
|
19
|
-
|
20
|
-
first_page.elements.must_equal [1, 2, 3]
|
21
|
-
end
|
26
|
+
context "when they are equal" do
|
22
27
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
28
|
+
before(:each) do
|
29
|
+
allow(other_page).to receive(:index).and_return(0)
|
30
|
+
allow(other_page).to receive(:elements).and_return(nil)
|
31
|
+
end
|
32
|
+
|
33
|
+
specify { expect(subject).to eq(true) }
|
34
|
+
end
|
29
35
|
|
30
|
-
|
31
|
-
|
32
|
-
|
36
|
+
context "when they are different" do
|
37
|
+
context "and the second has different values" do
|
38
|
+
before(:each) do
|
39
|
+
allow(other_page).to receive(:index).and_return(1)
|
40
|
+
allow(other_page).to receive(:elements).and_return([])
|
41
|
+
end
|
42
|
+
|
43
|
+
specify { expect(subject).to eq(false) }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
33
47
|
end
|
34
48
|
|
35
|
-
|
36
|
-
|
37
|
-
|
49
|
+
context "when has elements" do
|
50
|
+
let(:page) { Page.new(1, [1,2,3,4,5,6,7,8,9], 3) }
|
51
|
+
subject { page }
|
52
|
+
|
53
|
+
describe "#elements" do
|
54
|
+
specify { expect(subject.elements).to eq([1,2,3]) }
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#next" do
|
58
|
+
specify { expect(subject.next).to be_instance_of(Page) }
|
59
|
+
specify { expect(subject.next.index).to eq(subject.index + 1) }
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "#previous" do
|
63
|
+
before(:each) { allow(page).to receive(:index).and_return(2) }
|
64
|
+
|
65
|
+
specify { expect(subject.previous).to be_instance_of(Page) }
|
66
|
+
specify { expect(subject.previous.index).to eq(subject.index - 1) }
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "#==" do
|
70
|
+
let(:other_page) { double }
|
71
|
+
subject { page == other_page }
|
72
|
+
|
73
|
+
context "when both are equal" do
|
74
|
+
before(:each) do
|
75
|
+
allow(other_page).to receive(:index).and_return(1)
|
76
|
+
allow(other_page).to receive(:elements).and_return([1,2,3])
|
77
|
+
end
|
78
|
+
|
79
|
+
specify { expect(subject).to eq(true) }
|
80
|
+
end
|
81
|
+
|
82
|
+
context "when they are different" do
|
83
|
+
context "because the second has different values" do
|
84
|
+
before(:each) do
|
85
|
+
allow(other_page).to receive(:index).and_return(1)
|
86
|
+
allow(other_page).to receive(:elements).and_return([])
|
87
|
+
end
|
88
|
+
|
89
|
+
specify { expect(subject).to eq(false) }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
38
93
|
end
|
39
94
|
end
|
data/spec/paginator_spec.rb
CHANGED
@@ -1,77 +1,76 @@
|
|
1
|
-
|
1
|
+
require_relative 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
include SimplyPaginate
|
4
4
|
|
5
5
|
describe Paginator do
|
6
|
-
|
6
|
+
let(:paginator) { Paginator.new([1,2,3,4,5,6,7,8,9], 3) }
|
7
|
+
subject { paginator }
|
7
8
|
|
8
|
-
|
9
|
+
describe "#[]" do
|
10
|
+
let (:index) { 1 }
|
11
|
+
context "there are no elements to paginate" do
|
12
|
+
before(:each) { allow(subject).to receive(:collection).and_return([]) }
|
9
13
|
|
10
|
-
|
14
|
+
specify { expect(subject[index]).to be_nil }
|
15
|
+
end
|
11
16
|
|
12
|
-
|
17
|
+
context "there is at least one element" do
|
18
|
+
let(:elements) { [1] }
|
19
|
+
before(:each) { allow(subject).to receive(:collection).and_return(elements) }
|
13
20
|
|
14
|
-
|
15
|
-
|
16
|
-
results = []
|
21
|
+
specify { expect(subject[index]).to be_instance_of(Page) }
|
22
|
+
end
|
17
23
|
|
18
|
-
|
19
|
-
|
20
|
-
|
24
|
+
context "index is zero" do
|
25
|
+
let(:zero_index) { 0 }
|
26
|
+
specify { expect(subject[zero_index]).to be_nil }
|
27
|
+
end
|
21
28
|
|
22
|
-
|
29
|
+
context "index is negative" do
|
30
|
+
let(:negative_index) { -1 }
|
31
|
+
specify { expect(subject[negative_index]).to be_nil }
|
23
32
|
end
|
24
33
|
|
25
|
-
|
26
|
-
|
34
|
+
context "index greater than amount of pages" do
|
35
|
+
specify { expect(subject[4]).to be_nil }
|
36
|
+
end
|
27
37
|
end
|
28
38
|
|
29
|
-
|
30
|
-
|
31
|
-
|
39
|
+
describe "iteration" do
|
40
|
+
describe "next!" do
|
41
|
+
context "iteration hasn't started" do
|
42
|
+
specify { expect { subject.next! }.to raise_error("You need to start before iterating") }
|
43
|
+
end
|
32
44
|
|
33
|
-
|
34
|
-
|
35
|
-
pages[1].wont_be_nil
|
36
|
-
pages[1].must_equal first_page
|
37
|
-
pages[4].must_equal last_page
|
38
|
-
pages[5].must_be_nil
|
39
|
-
end
|
45
|
+
context "iteration started" do
|
46
|
+
before(:each) { subject.start }
|
40
47
|
|
41
|
-
|
42
|
-
|
43
|
-
|
48
|
+
specify do
|
49
|
+
expect(subject.next!).to be_instance_of(Page)
|
50
|
+
end
|
51
|
+
end
|
44
52
|
|
45
|
-
|
46
|
-
|
47
|
-
end
|
53
|
+
context "there are no more pages" do
|
54
|
+
before(:each) { allow(subject).to receive(:current).and_return(nil) }
|
48
55
|
|
49
|
-
|
50
|
-
|
51
|
-
lambda { pages.next! }.must_raise NoMethodError
|
52
|
-
end
|
53
|
-
|
54
|
-
it "must move to the next page using 'next!'" do
|
55
|
-
iteration_pages = pages
|
56
|
-
iteration_pages.start
|
57
|
-
iteration_pages.next!
|
58
|
-
iteration_pages.current.must_equal build_page(2)
|
56
|
+
specify { expect { subject.next! }.to raise_error("You need to start before iterating") }
|
57
|
+
end
|
59
58
|
end
|
59
|
+
end
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
61
|
+
describe "initialize" do
|
62
|
+
describe "without setting a per page" do
|
63
|
+
specify "it falls back to class level per_page" do
|
64
|
+
paginator = Paginator.new([0,1,2,3,4,5,6,7,8,9])
|
65
|
+
expect(paginator.first.elements.count).to eq(10)
|
66
|
+
end
|
66
67
|
end
|
67
68
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
4.times { iteration_pages.next! }
|
74
|
-
iteration_pages.next?.must_equal false
|
69
|
+
describe "setting a per page" do
|
70
|
+
specify "it falls back to class level per_page" do
|
71
|
+
paginator = Paginator.new([0,1,2,3,4,5,6,7,8,9], 3)
|
72
|
+
expect(paginator.first.elements.count).to eq(3)
|
73
|
+
end
|
75
74
|
end
|
76
75
|
end
|
77
76
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,2 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
Bundler.require
|
4
|
-
|
5
|
-
module Helpers
|
6
|
-
def page_array_collection
|
7
|
-
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
8
|
-
end
|
9
|
-
|
10
|
-
def build_page(number)
|
11
|
-
lambda { Page.new number, page_array_collection, 3 }.call
|
12
|
-
end
|
13
|
-
end
|
1
|
+
require 'rspec'
|
2
|
+
require 'simply_paginate'
|
metadata
CHANGED
@@ -1,62 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simply_paginate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.5
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Álvaro F. Lara
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2016-09-27 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '1.3'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '1.3'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
28
|
+
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rake
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
description: This gem is a simple paginator for Enumerable collections
|
@@ -66,9 +59,10 @@ executables: []
|
|
66
59
|
extensions: []
|
67
60
|
extra_rdoc_files: []
|
68
61
|
files:
|
69
|
-
- .gitignore
|
70
|
-
- .travis.yml
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
71
64
|
- Gemfile
|
65
|
+
- Gemfile.lock
|
72
66
|
- LICENSE.txt
|
73
67
|
- README.md
|
74
68
|
- Rakefile
|
@@ -86,30 +80,28 @@ files:
|
|
86
80
|
homepage: https://github.com/guiman/simply_paginate
|
87
81
|
licenses:
|
88
82
|
- MIT
|
83
|
+
metadata: {}
|
89
84
|
post_install_message:
|
90
85
|
rdoc_options: []
|
91
86
|
require_paths:
|
92
87
|
- lib
|
93
88
|
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
-
none: false
|
95
89
|
requirements:
|
96
|
-
- -
|
90
|
+
- - ">="
|
97
91
|
- !ruby/object:Gem::Version
|
98
92
|
version: '0'
|
99
93
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
-
none: false
|
101
94
|
requirements:
|
102
|
-
- -
|
95
|
+
- - ">="
|
103
96
|
- !ruby/object:Gem::Version
|
104
97
|
version: '0'
|
105
98
|
requirements: []
|
106
99
|
rubyforge_project:
|
107
|
-
rubygems_version:
|
100
|
+
rubygems_version: 2.5.1
|
108
101
|
signing_key:
|
109
|
-
specification_version:
|
102
|
+
specification_version: 4
|
110
103
|
summary: You enumerate it we will simply paginate it
|
111
104
|
test_files:
|
112
105
|
- spec/page_spec.rb
|
113
106
|
- spec/paginator_spec.rb
|
114
107
|
- spec/spec_helper.rb
|
115
|
-
has_rdoc:
|