mongoid_will_paginate 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -1
- data/.rspec +1 -1
- data/Gemfile +0 -10
- data/Gemfile.lock +142 -0
- data/README.md +14 -0
- data/lib/mongoid_will_paginate.rb +1 -1
- data/lib/mongoid_will_paginate/criteria.rb +13 -4
- data/lib/mongoid_will_paginate/version.rb +1 -1
- data/mongoid_will_paginate.gemspec +4 -6
- data/spec/mongoid_will_paginate_spec.rb +27 -27
- data/spec/rails_app.rb +1 -0
- data/spec/spec_helper.rb +30 -8
- metadata +47 -33
- data/README +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f65734b5606dcc3a1c67b35eddf77e2b03fac672
|
4
|
+
data.tar.gz: e061b017085255cdcadc3513fa34db3e0529abf5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e14c8cf4319bb9b3a7c22be2c078c2ec76507bfbc772b13f659151c6494d420c202b165f48066fcfa5812584df5d43d16af7b373e6382df4b1c9540cccf62f75
|
7
|
+
data.tar.gz: 6ab43db29d0332c3b01919865cf1dd9e14e921ca900c1a2f6ff352d6c3b4664986b59d5f1ae9a1454b64fdeff569cde4fa4abc78bfa1bda16a22235ac767429a
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
--color
|
2
|
-
--format
|
2
|
+
--format progress
|
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
mongoid_will_paginate (0.1.0)
|
5
|
+
mongoid (>= 5.0.0)
|
6
|
+
will_paginate (>= 3.0.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionmailer (4.2.6)
|
12
|
+
actionpack (= 4.2.6)
|
13
|
+
actionview (= 4.2.6)
|
14
|
+
activejob (= 4.2.6)
|
15
|
+
mail (~> 2.5, >= 2.5.4)
|
16
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
17
|
+
actionpack (4.2.6)
|
18
|
+
actionview (= 4.2.6)
|
19
|
+
activesupport (= 4.2.6)
|
20
|
+
rack (~> 1.6)
|
21
|
+
rack-test (~> 0.6.2)
|
22
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
23
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
24
|
+
actionview (4.2.6)
|
25
|
+
activesupport (= 4.2.6)
|
26
|
+
builder (~> 3.1)
|
27
|
+
erubis (~> 2.7.0)
|
28
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
29
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
30
|
+
activejob (4.2.6)
|
31
|
+
activesupport (= 4.2.6)
|
32
|
+
globalid (>= 0.3.0)
|
33
|
+
activemodel (4.2.6)
|
34
|
+
activesupport (= 4.2.6)
|
35
|
+
builder (~> 3.1)
|
36
|
+
activerecord (4.2.6)
|
37
|
+
activemodel (= 4.2.6)
|
38
|
+
activesupport (= 4.2.6)
|
39
|
+
arel (~> 6.0)
|
40
|
+
activesupport (4.2.6)
|
41
|
+
i18n (~> 0.7)
|
42
|
+
json (~> 1.7, >= 1.7.7)
|
43
|
+
minitest (~> 5.1)
|
44
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
45
|
+
tzinfo (~> 1.1)
|
46
|
+
arel (6.0.3)
|
47
|
+
bson (4.1.0)
|
48
|
+
builder (3.2.2)
|
49
|
+
concurrent-ruby (1.0.1)
|
50
|
+
diff-lcs (1.2.5)
|
51
|
+
erubis (2.7.0)
|
52
|
+
globalid (0.3.6)
|
53
|
+
activesupport (>= 4.1.0)
|
54
|
+
i18n (0.7.0)
|
55
|
+
json (1.8.3)
|
56
|
+
loofah (2.0.3)
|
57
|
+
nokogiri (>= 1.5.9)
|
58
|
+
mail (2.6.4)
|
59
|
+
mime-types (>= 1.16, < 4)
|
60
|
+
mime-types (3.0)
|
61
|
+
mime-types-data (~> 3.2015)
|
62
|
+
mime-types-data (3.2016.0221)
|
63
|
+
mini_portile2 (2.0.0)
|
64
|
+
minitest (5.8.4)
|
65
|
+
mongo (2.2.4)
|
66
|
+
bson (~> 4.0)
|
67
|
+
mongoid (5.1.2)
|
68
|
+
activemodel (~> 4.0)
|
69
|
+
mongo (~> 2.1)
|
70
|
+
origin (~> 2.2)
|
71
|
+
tzinfo (>= 0.3.37)
|
72
|
+
nokogiri (1.6.7.2)
|
73
|
+
mini_portile2 (~> 2.0.0.rc2)
|
74
|
+
origin (2.2.0)
|
75
|
+
rack (1.6.4)
|
76
|
+
rack-test (0.6.3)
|
77
|
+
rack (>= 1.0)
|
78
|
+
rails (4.2.6)
|
79
|
+
actionmailer (= 4.2.6)
|
80
|
+
actionpack (= 4.2.6)
|
81
|
+
actionview (= 4.2.6)
|
82
|
+
activejob (= 4.2.6)
|
83
|
+
activemodel (= 4.2.6)
|
84
|
+
activerecord (= 4.2.6)
|
85
|
+
activesupport (= 4.2.6)
|
86
|
+
bundler (>= 1.3.0, < 2.0)
|
87
|
+
railties (= 4.2.6)
|
88
|
+
sprockets-rails
|
89
|
+
rails-deprecated_sanitizer (1.0.3)
|
90
|
+
activesupport (>= 4.2.0.alpha)
|
91
|
+
rails-dom-testing (1.0.7)
|
92
|
+
activesupport (>= 4.2.0.beta, < 5.0)
|
93
|
+
nokogiri (~> 1.6.0)
|
94
|
+
rails-deprecated_sanitizer (>= 1.0.1)
|
95
|
+
rails-html-sanitizer (1.0.3)
|
96
|
+
loofah (~> 2.0)
|
97
|
+
railties (4.2.6)
|
98
|
+
actionpack (= 4.2.6)
|
99
|
+
activesupport (= 4.2.6)
|
100
|
+
rake (>= 0.8.7)
|
101
|
+
thor (>= 0.18.1, < 2.0)
|
102
|
+
rake (11.1.2)
|
103
|
+
rspec-core (3.4.4)
|
104
|
+
rspec-support (~> 3.4.0)
|
105
|
+
rspec-expectations (3.4.0)
|
106
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
107
|
+
rspec-support (~> 3.4.0)
|
108
|
+
rspec-mocks (3.4.1)
|
109
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
110
|
+
rspec-support (~> 3.4.0)
|
111
|
+
rspec-rails (3.4.2)
|
112
|
+
actionpack (>= 3.0, < 4.3)
|
113
|
+
activesupport (>= 3.0, < 4.3)
|
114
|
+
railties (>= 3.0, < 4.3)
|
115
|
+
rspec-core (~> 3.4.0)
|
116
|
+
rspec-expectations (~> 3.4.0)
|
117
|
+
rspec-mocks (~> 3.4.0)
|
118
|
+
rspec-support (~> 3.4.0)
|
119
|
+
rspec-support (3.4.1)
|
120
|
+
sprockets (3.6.0)
|
121
|
+
concurrent-ruby (~> 1.0)
|
122
|
+
rack (> 1, < 3)
|
123
|
+
sprockets-rails (3.0.4)
|
124
|
+
actionpack (>= 4.0)
|
125
|
+
activesupport (>= 4.0)
|
126
|
+
sprockets (>= 3.0.0)
|
127
|
+
thor (0.19.1)
|
128
|
+
thread_safe (0.3.5)
|
129
|
+
tzinfo (1.2.2)
|
130
|
+
thread_safe (~> 0.1)
|
131
|
+
will_paginate (3.1.0)
|
132
|
+
|
133
|
+
PLATFORMS
|
134
|
+
ruby
|
135
|
+
|
136
|
+
DEPENDENCIES
|
137
|
+
mongoid_will_paginate!
|
138
|
+
rails (>= 3.0.0)
|
139
|
+
rspec-rails (>= 3.4.0)
|
140
|
+
|
141
|
+
BUNDLED WITH
|
142
|
+
1.11.2
|
data/README.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Overview
|
2
|
+
========
|
3
|
+
|
4
|
+
mongoid_will_pagnate is a gem for native support of will_paginate for mongoid.
|
5
|
+
It allows you to do lazy load of your collections with pagination using native calls to Mongoid::Collection#skip and Mongoid::Collection#limit.
|
6
|
+
|
7
|
+
How to use
|
8
|
+
==========
|
9
|
+
|
10
|
+
Just add this gem to your Gemfile:
|
11
|
+
|
12
|
+
gem 'mongoid_will_paginate'
|
13
|
+
|
14
|
+
and you can use will_paginate without fetching all collection objects to array (like it does internally) while paginating.
|
@@ -2,13 +2,22 @@ require 'will_paginate/collection'
|
|
2
2
|
|
3
3
|
module MongoidWillPaginate
|
4
4
|
module Criteria
|
5
|
-
|
5
|
+
def self.extended(base)
|
6
|
+
base.include InstanceMethods
|
7
|
+
end
|
6
8
|
|
7
|
-
|
9
|
+
module InstanceMethods
|
10
|
+
# Paginates criteria depending on the options given
|
11
|
+
#
|
12
|
+
# @param [Hash] options pagination options
|
13
|
+
# @option options [Fixnum] :page page number
|
14
|
+
# @option options [Fixnum] :per_page number of entries per page
|
15
|
+
# @option options [Fixnum] :total_entries total number of entries
|
16
|
+
# @return [WillPaginate::Collection] paginated collection of entries
|
8
17
|
def paginate(options = {})
|
9
|
-
page
|
18
|
+
page = options[:page] || 1
|
10
19
|
per_page = options[:per_page] || WillPaginate.per_page
|
11
|
-
total
|
20
|
+
total = options[:total_entries] || self.count
|
12
21
|
|
13
22
|
WillPaginate::Collection.create(page, per_page, total) do |pager|
|
14
23
|
pager.replace self.skip(pager.offset).limit(pager.per_page).to_a
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
1
|
$:.push File.expand_path("../lib", __FILE__)
|
3
2
|
require "mongoid_will_paginate/version"
|
4
3
|
|
@@ -17,10 +16,9 @@ Gem::Specification.new do |s|
|
|
17
16
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
17
|
s.require_paths = ["lib"]
|
19
18
|
|
20
|
-
|
21
|
-
s.add_development_dependency "
|
22
|
-
|
23
|
-
|
24
|
-
s.add_runtime_dependency "mongoid", [">= 2.1.0"]
|
19
|
+
s.add_development_dependency "rspec-rails", [">= 3.4.0"]
|
20
|
+
s.add_development_dependency "rails", [">= 3.0.0"]
|
21
|
+
|
22
|
+
s.add_runtime_dependency "mongoid", [">= 5.0.0"]
|
25
23
|
s.add_runtime_dependency "will_paginate", [">= 3.0.0"]
|
26
24
|
end
|
@@ -1,35 +1,35 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
describe MongoidWillPaginate::Criteria do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
field :title, type: String
|
8
|
-
end
|
3
|
+
RSpec.describe MongoidWillPaginate::Criteria do
|
4
|
+
class Document
|
5
|
+
include ::Mongoid::Document
|
6
|
+
field :title, type: String
|
9
7
|
end
|
10
|
-
|
11
|
-
describe :paginate do
|
12
|
-
context 'called in a Mongoid::Criteria' do
|
13
|
-
before :each do
|
14
|
-
@docs = 15.times.map{|i| Document.create title: 'document title'}
|
15
|
-
15.times{Document.create title: 'document title 2'}
|
16
8
|
|
17
|
-
|
18
|
-
|
9
|
+
describe '#paginate' do
|
10
|
+
let!(:docs) do
|
11
|
+
15.times.map { Document.create(title: 'document title') }
|
12
|
+
end
|
13
|
+
let(:criteria) { Document.where(title: 'document title') }
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
15.times { Document.create(title: 'document title 2') }
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'when paginate params specified' do
|
20
|
+
subject { criteria.paginate(page: 2, per_page: 5) }
|
21
|
+
|
22
|
+
it { expect(subject).to be_a_instance_of(WillPaginate::Collection) }
|
23
|
+
it { expect(subject.to_a).to eq(docs[5..9]) }
|
24
|
+
it { expect(subject.total_entries).to eq(criteria.count) }
|
25
|
+
end
|
19
26
|
|
20
|
-
|
21
|
-
|
22
|
-
it {should be_a_instance_of WillPaginate::Collection}
|
23
|
-
its(:to_a) {should == @docs[5..9]}
|
24
|
-
its(:total_entries) {should == @criteria.count}
|
25
|
-
end
|
27
|
+
context 'when paginate parameters not specified' do
|
28
|
+
subject { criteria.paginate }
|
26
29
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
its(:to_a) {should == @docs}
|
31
|
-
its(:total_entries) {should == @criteria.count}
|
32
|
-
end
|
30
|
+
it { expect(subject).to be_a_instance_of(WillPaginate::Collection) }
|
31
|
+
it { expect(subject.to_a).to eq(docs) }
|
32
|
+
it { expect(subject.total_entries).to eq(criteria.count) }
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
data/spec/rails_app.rb
CHANGED
@@ -6,4 +6,5 @@ app = Class.new(Rails::Application)
|
|
6
6
|
app.config.secret_token = Digest::MD5.hexdigest("mongoid_will_paginate")
|
7
7
|
app.config.session_store :cookie_store, :key => "_test_rails_app_session"
|
8
8
|
app.config.active_support.deprecation = :log
|
9
|
+
app.config.eager_load = false
|
9
10
|
app.initialize!
|
data/spec/spec_helper.rb
CHANGED
@@ -1,21 +1,43 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require 'bundler/setup'
|
3
2
|
|
4
3
|
require 'rails'
|
5
4
|
require 'mongoid'
|
6
5
|
require 'will_paginate'
|
7
6
|
require 'mongoid_will_paginate'
|
8
7
|
|
9
|
-
require
|
8
|
+
require 'rails_app'
|
10
9
|
require 'rspec/rails'
|
11
10
|
|
12
|
-
|
11
|
+
Mongoid.configure do |config|
|
12
|
+
config.connect_to 'test_mongoid_will_paginate'
|
13
|
+
end
|
14
|
+
|
15
|
+
Mongoid.logger.level = Logger::ERROR
|
16
|
+
Mongo::Logger.logger.level = Logger::ERROR
|
13
17
|
|
14
18
|
RSpec.configure do |config|
|
15
|
-
config.
|
16
|
-
|
17
|
-
Mongoid.master.collections.select{|c| c.name !~ /system/}.each(&:drop)
|
19
|
+
config.expect_with :rspec do |expectations|
|
20
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
18
21
|
end
|
19
|
-
end
|
20
22
|
|
21
|
-
|
23
|
+
config.mock_with :rspec do |mocks|
|
24
|
+
mocks.verify_partial_doubles = true
|
25
|
+
end
|
26
|
+
|
27
|
+
config.filter_run :focus
|
28
|
+
config.run_all_when_everything_filtered = true
|
29
|
+
|
30
|
+
config.example_status_persistence_file_path = 'spec/examples.txt'
|
31
|
+
|
32
|
+
config.disable_monkey_patching!
|
33
|
+
|
34
|
+
config.profile_examples = 10
|
35
|
+
|
36
|
+
config.order = :random
|
37
|
+
|
38
|
+
Kernel.srand config.seed
|
39
|
+
|
40
|
+
config.before(:each) do
|
41
|
+
Mongoid.default_client.collections.select{ |c| c.name !~ /system/ }.each(&:drop)
|
42
|
+
end
|
43
|
+
end
|
metadata
CHANGED
@@ -1,60 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_will_paginate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Hck
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2016-04-20 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name: rspec
|
16
|
-
requirement:
|
17
|
-
none: false
|
14
|
+
name: rspec-rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
19
|
+
version: 3.4.0
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.4.0
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: rails
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - ">="
|
31
32
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
33
|
+
version: 3.0.0
|
33
34
|
type: :development
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.0.0
|
36
41
|
- !ruby/object:Gem::Dependency
|
37
42
|
name: mongoid
|
38
|
-
requirement:
|
39
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
40
44
|
requirements:
|
41
|
-
- -
|
45
|
+
- - ">="
|
42
46
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
47
|
+
version: 5.0.0
|
44
48
|
type: :runtime
|
45
49
|
prerelease: false
|
46
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 5.0.0
|
47
55
|
- !ruby/object:Gem::Dependency
|
48
56
|
name: will_paginate
|
49
|
-
requirement:
|
50
|
-
none: false
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
51
58
|
requirements:
|
52
|
-
- -
|
59
|
+
- - ">="
|
53
60
|
- !ruby/object:Gem::Version
|
54
61
|
version: 3.0.0
|
55
62
|
type: :runtime
|
56
63
|
prerelease: false
|
57
|
-
version_requirements:
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.0.0
|
58
69
|
description: Simple native pagination extension for will_paginate using mongoid skip
|
59
70
|
and limit methods
|
60
71
|
email:
|
@@ -62,10 +73,11 @@ executables: []
|
|
62
73
|
extensions: []
|
63
74
|
extra_rdoc_files: []
|
64
75
|
files:
|
65
|
-
- .gitignore
|
66
|
-
- .rspec
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
67
78
|
- Gemfile
|
68
|
-
-
|
79
|
+
- Gemfile.lock
|
80
|
+
- README.md
|
69
81
|
- Rakefile
|
70
82
|
- lib/mongoid_will_paginate.rb
|
71
83
|
- lib/mongoid_will_paginate/criteria.rb
|
@@ -76,26 +88,28 @@ files:
|
|
76
88
|
- spec/spec_helper.rb
|
77
89
|
homepage: ''
|
78
90
|
licenses: []
|
91
|
+
metadata: {}
|
79
92
|
post_install_message:
|
80
93
|
rdoc_options: []
|
81
94
|
require_paths:
|
82
95
|
- lib
|
83
96
|
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
-
none: false
|
85
97
|
requirements:
|
86
|
-
- -
|
98
|
+
- - ">="
|
87
99
|
- !ruby/object:Gem::Version
|
88
100
|
version: '0'
|
89
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
-
none: false
|
91
102
|
requirements:
|
92
|
-
- -
|
103
|
+
- - ">="
|
93
104
|
- !ruby/object:Gem::Version
|
94
105
|
version: '0'
|
95
106
|
requirements: []
|
96
107
|
rubyforge_project: mongoid_will_paginate
|
97
|
-
rubygems_version:
|
108
|
+
rubygems_version: 2.5.1
|
98
109
|
signing_key:
|
99
|
-
specification_version:
|
110
|
+
specification_version: 4
|
100
111
|
summary: Simple native pagination extension for will_paginate
|
101
|
-
test_files:
|
112
|
+
test_files:
|
113
|
+
- spec/mongoid_will_paginate_spec.rb
|
114
|
+
- spec/rails_app.rb
|
115
|
+
- spec/spec_helper.rb
|
data/README
DELETED
File without changes
|