will_paginate_mongoid 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +6 -0
- data/.rspec +1 -0
- data/Gemfile +13 -0
- data/README +0 -0
- data/Rakefile +1 -0
- data/lib/will_paginate_mongoid/engine.rb +11 -0
- data/lib/will_paginate_mongoid/mongoid_paginator.rb +31 -0
- data/lib/will_paginate_mongoid/version.rb +3 -0
- data/lib/will_paginate_mongoid.rb +3 -0
- data/spec/fake_app.rb +8 -0
- data/spec/integration/mongoid_paginator_spec.rb +62 -0
- data/spec/spec_helper.rb +22 -0
- data/will_paginate_mongoid.gemspec +23 -0
- metadata +111 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/README
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require 'mongoid'
|
3
|
+
|
4
|
+
module WillPaginateMongoid
|
5
|
+
class Engine < ::Rails::Engine
|
6
|
+
initializer "including extensions" do
|
7
|
+
::Mongoid::Document.send :include, WillPaginateMongoid::MongoidPaginator
|
8
|
+
::Mongoid::Criteria.send :include, WillPaginateMongoid::MongoidPaginator
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module WillPaginateMongoid
|
2
|
+
DEFAULT_PER_PAGE = 10
|
3
|
+
|
4
|
+
module MongoidPaginator
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
def self.paginate(options = {})
|
9
|
+
options = base_options options
|
10
|
+
|
11
|
+
WillPaginate::Collection.create(options[:page], options[:per_page]) do |pager|
|
12
|
+
fill_pager_with self.skip(options[:offset]).limit(options[:per_page]), self.count, pager
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def self.base_options(options)
|
19
|
+
options[:page] ||= 1
|
20
|
+
options[:per_page] ||= 10
|
21
|
+
options[:offset] = (options[:page].to_i - 1) * options[:per_page]
|
22
|
+
options
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.fill_pager_with(medias, size, pager)
|
26
|
+
pager.replace medias.to_a
|
27
|
+
pager.total_entries = size
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/spec/fake_app.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'action_controller/railtie'
|
2
|
+
require 'action_view/railtie'
|
3
|
+
|
4
|
+
app = Class.new(Rails::Application)
|
5
|
+
app.config.secret_token = "3b7cd727ee24e8444053437c36cc66c4"
|
6
|
+
app.config.session_store :cookie_store, :key => "_myapp_session"
|
7
|
+
app.config.active_support.deprecation = :log
|
8
|
+
app.initialize!
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe WillPaginateMongoid::MongoidPaginator do
|
4
|
+
before :all do
|
5
|
+
class Game
|
6
|
+
include ::Mongoid::Document
|
7
|
+
field :title, :type => String
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe :paginate do
|
12
|
+
context "when called in a Mongoid::Document" do
|
13
|
+
before :each do
|
14
|
+
@games = 30.times.map do |i|
|
15
|
+
Game.create :title => "title_#{i}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "and parameters is given" do
|
20
|
+
subject { Game.paginate :page => 2, :per_page => 10 }
|
21
|
+
it { should be_a_instance_of WillPaginate::Collection }
|
22
|
+
its(:to_a) { should == @games[10..19] }
|
23
|
+
its(:total_entries) { should == Game.count }
|
24
|
+
end
|
25
|
+
|
26
|
+
context "and parameters is not given" do
|
27
|
+
subject { Game.paginate }
|
28
|
+
it { should be_a_instance_of WillPaginate::Collection }
|
29
|
+
its(:to_a) { should == @games[0..9] }
|
30
|
+
its(:total_entries) { should == 30 }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "when called in a Mongoid::Criteria" do
|
35
|
+
before :each do
|
36
|
+
@games = 15.times.map do |i|
|
37
|
+
Game.create :title => "title"
|
38
|
+
end
|
39
|
+
|
40
|
+
15.times do
|
41
|
+
Game.create :title => "other title"
|
42
|
+
end
|
43
|
+
|
44
|
+
@criteria = Game.where(:title => "title")
|
45
|
+
end
|
46
|
+
|
47
|
+
context "and parameters is given" do
|
48
|
+
subject { @criteria.paginate :page => 2, :per_page => 10 }
|
49
|
+
it { should be_a_instance_of WillPaginate::Collection }
|
50
|
+
its(:to_a) { should == @games[10..14] }
|
51
|
+
its(:total_entries) { should == @criteria.count }
|
52
|
+
end
|
53
|
+
|
54
|
+
context "and parameters is not given" do
|
55
|
+
subject { @criteria.paginate }
|
56
|
+
it { should be_a_instance_of WillPaginate::Collection }
|
57
|
+
its(:to_a) { should == @games[0..9] }
|
58
|
+
its(:total_entries) { should == @criteria.count }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require 'mongoid'
|
3
|
+
require 'will_paginate'
|
4
|
+
require 'will_paginate_mongoid'
|
5
|
+
|
6
|
+
require File.join(File.dirname(__FILE__), 'fake_app')
|
7
|
+
require 'rspec/rails'
|
8
|
+
|
9
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.mock_with :rspec
|
13
|
+
config.before :each do
|
14
|
+
Mongoid.master.collections.select do |collection|
|
15
|
+
collection.name !~ /system/
|
16
|
+
end.each(&:drop)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Mongoid.configure do |config|
|
21
|
+
config.master = Mongo::Connection.new.db("will_paginate_mongoid")
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "will_paginate_mongoid/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "will_paginate_mongoid"
|
7
|
+
s.version = WillPaginateMongoid::VERSION
|
8
|
+
s.authors = ["Lucas Souza"]
|
9
|
+
s.email = ["lucasas@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = "An extension that becomes possible use paginate method with Mongoid"
|
12
|
+
s.description = ""
|
13
|
+
|
14
|
+
s.rubyforge_project = "will_paginate_mongoid"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_runtime_dependency "mongoid", "~> 2.2.2"
|
22
|
+
s.add_runtime_dependency "will_paginate", "~> 3.0.2"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: will_paginate_mongoid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Lucas Souza
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-10-20 00:00:00 -02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: mongoid
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 2
|
33
|
+
- 2
|
34
|
+
version: 2.2.2
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: will_paginate
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 3
|
48
|
+
- 0
|
49
|
+
- 2
|
50
|
+
version: 3.0.2
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
description: ""
|
54
|
+
email:
|
55
|
+
- lucasas@gmail.com
|
56
|
+
executables: []
|
57
|
+
|
58
|
+
extensions: []
|
59
|
+
|
60
|
+
extra_rdoc_files: []
|
61
|
+
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- .rspec
|
65
|
+
- Gemfile
|
66
|
+
- README
|
67
|
+
- Rakefile
|
68
|
+
- lib/will_paginate_mongoid.rb
|
69
|
+
- lib/will_paginate_mongoid/engine.rb
|
70
|
+
- lib/will_paginate_mongoid/mongoid_paginator.rb
|
71
|
+
- lib/will_paginate_mongoid/version.rb
|
72
|
+
- spec/fake_app.rb
|
73
|
+
- spec/integration/mongoid_paginator_spec.rb
|
74
|
+
- spec/spec_helper.rb
|
75
|
+
- will_paginate_mongoid.gemspec
|
76
|
+
has_rdoc: true
|
77
|
+
homepage: ""
|
78
|
+
licenses: []
|
79
|
+
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
requirements: []
|
104
|
+
|
105
|
+
rubyforge_project: will_paginate_mongoid
|
106
|
+
rubygems_version: 1.6.2
|
107
|
+
signing_key:
|
108
|
+
specification_version: 3
|
109
|
+
summary: An extension that becomes possible use paginate method with Mongoid
|
110
|
+
test_files: []
|
111
|
+
|