kaminari 0.17.0 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.codeclimate.yml +19 -0
- data/.github/workflows/main.yml +107 -0
- data/.gitignore +2 -1
- data/CHANGELOG.md +650 -0
- data/CONTRIBUTING.md +22 -0
- data/Gemfile +2 -0
- data/README.md +588 -0
- data/Rakefile +25 -25
- data/gemfiles/active_record_41.gemfile +17 -12
- data/gemfiles/active_record_42.gemfile +17 -12
- data/gemfiles/active_record_50.gemfile +26 -0
- data/gemfiles/active_record_51.gemfile +26 -0
- data/gemfiles/active_record_52.gemfile +26 -0
- data/gemfiles/active_record_60.gemfile +28 -0
- data/gemfiles/active_record_61.gemfile +28 -0
- data/gemfiles/active_record_70.gemfile +28 -0
- data/gemfiles/active_record_edge.gemfile +22 -17
- data/kaminari.gemspec +23 -27
- data/lib/kaminari/version.rb +3 -1
- data/lib/kaminari.rb +4 -38
- data/misc/bug_report_template.rb +57 -0
- metadata +54 -190
- data/.gemtest +0 -0
- data/.rspec +0 -2
- data/.travis.yml +0 -64
- data/CHANGELOG.rdoc +0 -480
- data/README.rdoc +0 -336
- data/app/views/kaminari/_first_page.html.erb +0 -11
- data/app/views/kaminari/_first_page.html.haml +0 -9
- data/app/views/kaminari/_first_page.html.slim +0 -10
- data/app/views/kaminari/_gap.html.erb +0 -8
- data/app/views/kaminari/_gap.html.haml +0 -8
- data/app/views/kaminari/_gap.html.slim +0 -9
- data/app/views/kaminari/_last_page.html.erb +0 -11
- data/app/views/kaminari/_last_page.html.haml +0 -9
- data/app/views/kaminari/_last_page.html.slim +0 -10
- data/app/views/kaminari/_next_page.html.erb +0 -11
- data/app/views/kaminari/_next_page.html.haml +0 -9
- data/app/views/kaminari/_next_page.html.slim +0 -10
- data/app/views/kaminari/_page.html.erb +0 -12
- data/app/views/kaminari/_page.html.haml +0 -10
- data/app/views/kaminari/_page.html.slim +0 -11
- data/app/views/kaminari/_paginator.html.erb +0 -23
- data/app/views/kaminari/_paginator.html.haml +0 -18
- data/app/views/kaminari/_paginator.html.slim +0 -19
- data/app/views/kaminari/_prev_page.html.erb +0 -11
- data/app/views/kaminari/_prev_page.html.haml +0 -9
- data/app/views/kaminari/_prev_page.html.slim +0 -10
- data/config/locales/kaminari.yml +0 -19
- data/gemfiles/active_record_30.gemfile +0 -28
- data/gemfiles/active_record_31.gemfile +0 -26
- data/gemfiles/active_record_32.gemfile +0 -25
- data/gemfiles/active_record_40.gemfile +0 -26
- data/gemfiles/data_mapper_12.gemfile +0 -32
- data/gemfiles/mongo_mapper.gemfile +0 -25
- data/gemfiles/mongoid_30.gemfile +0 -22
- data/gemfiles/mongoid_31.gemfile +0 -21
- data/gemfiles/mongoid_40.gemfile +0 -19
- data/gemfiles/mongoid_50.gemfile +0 -23
- data/gemfiles/sinatra_13.gemfile +0 -36
- data/gemfiles/sinatra_14.gemfile +0 -33
- data/lib/generators/kaminari/config_generator.rb +0 -16
- data/lib/generators/kaminari/templates/kaminari_config.rb +0 -10
- data/lib/generators/kaminari/views_generator.rb +0 -119
- data/lib/kaminari/config.rb +0 -51
- data/lib/kaminari/engine.rb +0 -4
- data/lib/kaminari/grape.rb +0 -4
- data/lib/kaminari/helpers/action_view_extension.rb +0 -132
- data/lib/kaminari/helpers/paginator.rb +0 -195
- data/lib/kaminari/helpers/sinatra_helpers.rb +0 -176
- data/lib/kaminari/helpers/tags.rb +0 -108
- data/lib/kaminari/hooks.rb +0 -53
- data/lib/kaminari/models/active_record_extension.rb +0 -22
- data/lib/kaminari/models/active_record_model_extension.rb +0 -22
- data/lib/kaminari/models/active_record_relation_methods.rb +0 -42
- data/lib/kaminari/models/array_extension.rb +0 -66
- data/lib/kaminari/models/configuration_methods.rb +0 -48
- data/lib/kaminari/models/data_mapper_collection_methods.rb +0 -19
- data/lib/kaminari/models/data_mapper_extension.rb +0 -51
- data/lib/kaminari/models/mongo_mapper_extension.rb +0 -18
- data/lib/kaminari/models/mongoid_criteria_methods.rb +0 -40
- data/lib/kaminari/models/mongoid_extension.rb +0 -26
- data/lib/kaminari/models/page_scope_methods.rb +0 -73
- data/lib/kaminari/models/plucky_criteria_methods.rb +0 -23
- data/lib/kaminari/railtie.rb +0 -7
- data/lib/kaminari/sinatra.rb +0 -7
- data/spec/config/config_spec.rb +0 -91
- data/spec/fake_app/active_record/config.rb +0 -3
- data/spec/fake_app/active_record/models.rb +0 -65
- data/spec/fake_app/data_mapper/config.rb +0 -1
- data/spec/fake_app/data_mapper/models.rb +0 -27
- data/spec/fake_app/mongo_mapper/config.rb +0 -2
- data/spec/fake_app/mongo_mapper/models.rb +0 -9
- data/spec/fake_app/mongoid/config.rb +0 -20
- data/spec/fake_app/mongoid/models.rb +0 -38
- data/spec/fake_app/rails_app.rb +0 -56
- data/spec/fake_app/sinatra_app.rb +0 -22
- data/spec/fake_app/views/alternative/kaminari/_first_page.html.erb +0 -1
- data/spec/fake_app/views/alternative/kaminari/_paginator.html.erb +0 -3
- data/spec/fake_app/views/kaminari/bootstrap/_page.html.erb +0 -1
- data/spec/fake_app/views/kaminari/bootstrap/_paginator.html.erb +0 -7
- data/spec/fake_gem.rb +0 -20
- data/spec/generators/views_generator_spec.rb +0 -18
- data/spec/helpers/action_view_extension_spec.rb +0 -318
- data/spec/helpers/helpers_spec.rb +0 -144
- data/spec/helpers/sinatra_helpers_spec.rb +0 -223
- data/spec/helpers/tags_spec.rb +0 -140
- data/spec/models/active_record/active_record_relation_methods_spec.rb +0 -77
- data/spec/models/active_record/inherited_spec.rb +0 -9
- data/spec/models/active_record/scopes_spec.rb +0 -265
- data/spec/models/array_spec.rb +0 -172
- data/spec/models/configuration_methods_spec.rb +0 -125
- data/spec/models/data_mapper/data_mapper_spec.rb +0 -205
- data/spec/models/mongo_mapper/mongo_mapper_spec.rb +0 -84
- data/spec/models/mongoid/mongoid_spec.rb +0 -228
- data/spec/requests/users_spec.rb +0 -53
- data/spec/spec_helper.rb +0 -34
- data/spec/spec_helper_for_sinatra.rb +0 -34
- data/spec/support/database_cleaner.rb +0 -19
- data/spec/support/matchers.rb +0 -52
@@ -1,48 +0,0 @@
|
|
1
|
-
module Kaminari
|
2
|
-
module ConfigurationMethods
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
module ClassMethods
|
5
|
-
# Overrides the default +per_page+ value per model
|
6
|
-
# class Article < ActiveRecord::Base
|
7
|
-
# paginates_per 10
|
8
|
-
# end
|
9
|
-
def paginates_per(val)
|
10
|
-
@_default_per_page = val
|
11
|
-
end
|
12
|
-
|
13
|
-
# This model's default +per_page+ value
|
14
|
-
# returns +default_per_page+ value unless explicitly overridden via <tt>paginates_per</tt>
|
15
|
-
def default_per_page
|
16
|
-
(defined?(@_default_per_page) && @_default_per_page) || Kaminari.config.default_per_page
|
17
|
-
end
|
18
|
-
|
19
|
-
# Overrides the max +per_page+ value per model
|
20
|
-
# class Article < ActiveRecord::Base
|
21
|
-
# max_paginates_per 100
|
22
|
-
# end
|
23
|
-
def max_paginates_per(val)
|
24
|
-
@_max_per_page = val
|
25
|
-
end
|
26
|
-
|
27
|
-
# This model's max +per_page+ value
|
28
|
-
# returns +max_per_page+ value unless explicitly overridden via <tt>max_paginates_per</tt>
|
29
|
-
def max_per_page
|
30
|
-
(defined?(@_max_per_page) && @_max_per_page) || Kaminari.config.max_per_page
|
31
|
-
end
|
32
|
-
|
33
|
-
# Overrides the max_pages value per model
|
34
|
-
# class Article < ActiveRecord::Base
|
35
|
-
# max_pages_per 100
|
36
|
-
# end
|
37
|
-
def max_pages_per(val)
|
38
|
-
@_max_pages = val
|
39
|
-
end
|
40
|
-
|
41
|
-
# This model's max_pages value
|
42
|
-
# returns max_pages value unless explicitly overridden via <tt>max_pages_per</tt>
|
43
|
-
def max_pages
|
44
|
-
(defined?(@_max_pages) && @_max_pages) || Kaminari.config.max_pages
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Kaminari
|
2
|
-
module DataMapperCollectionMethods
|
3
|
-
def entry_name
|
4
|
-
model.model_name.human.downcase
|
5
|
-
end
|
6
|
-
|
7
|
-
def limit_value #:nodoc:
|
8
|
-
query.options[:limit] || 0
|
9
|
-
end
|
10
|
-
|
11
|
-
def offset_value #:nodoc:
|
12
|
-
query.options[:offset] || 0
|
13
|
-
end
|
14
|
-
|
15
|
-
def total_count #:nodoc:
|
16
|
-
model.count(query.options.except(:limit, :offset, :order))
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'kaminari/models/data_mapper_collection_methods'
|
2
|
-
|
3
|
-
module Kaminari
|
4
|
-
module DataMapperExtension
|
5
|
-
module Paginatable
|
6
|
-
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
7
|
-
def #{Kaminari.config.page_method_name}(num = 1)
|
8
|
-
model = self
|
9
|
-
model = self.model if self.is_a? DataMapper::Collection
|
10
|
-
num = [num.to_i, 1].max - 1
|
11
|
-
all(:limit => model.default_per_page, :offset => model.default_per_page * num).extend Paginating
|
12
|
-
end
|
13
|
-
RUBY
|
14
|
-
end
|
15
|
-
|
16
|
-
module Paginating
|
17
|
-
include Kaminari::PageScopeMethods
|
18
|
-
|
19
|
-
def all(options={})
|
20
|
-
super.extend Paginating
|
21
|
-
end
|
22
|
-
|
23
|
-
def per(num)
|
24
|
-
super.extend Paginating
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
module Collection
|
29
|
-
extend ActiveSupport::Concern
|
30
|
-
included do
|
31
|
-
include Kaminari::DataMapperCollectionMethods
|
32
|
-
include Paginatable
|
33
|
-
|
34
|
-
delegate :default_per_page, :max_per_page, :max_pages, :to => :model
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
module Model
|
39
|
-
include Kaminari::ConfigurationMethods::ClassMethods
|
40
|
-
include Paginatable
|
41
|
-
|
42
|
-
def limit(val)
|
43
|
-
all(:limit => val)
|
44
|
-
end
|
45
|
-
|
46
|
-
def offset(val)
|
47
|
-
all(:offset => val)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'kaminari/models/plucky_criteria_methods'
|
2
|
-
|
3
|
-
module Kaminari
|
4
|
-
module MongoMapperExtension
|
5
|
-
module Document
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
include Kaminari::ConfigurationMethods
|
8
|
-
|
9
|
-
included do
|
10
|
-
# Fetch the values at the specified page number
|
11
|
-
# Model.page(5)
|
12
|
-
scope Kaminari.config.page_method_name, Proc.new {|num|
|
13
|
-
limit(default_per_page).offset(default_per_page * ([num.to_i, 1].max - 1))
|
14
|
-
}
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module Kaminari
|
2
|
-
module MongoidCriteriaMethods
|
3
|
-
def initialize_copy(other) #:nodoc:
|
4
|
-
@total_count = nil
|
5
|
-
super
|
6
|
-
end
|
7
|
-
|
8
|
-
def entry_name
|
9
|
-
model_name.human.downcase
|
10
|
-
end
|
11
|
-
|
12
|
-
def limit_value #:nodoc:
|
13
|
-
options[:limit]
|
14
|
-
end
|
15
|
-
|
16
|
-
def offset_value #:nodoc:
|
17
|
-
options[:skip]
|
18
|
-
end
|
19
|
-
|
20
|
-
def total_count #:nodoc:
|
21
|
-
@total_count ||= if embedded?
|
22
|
-
unpage.count
|
23
|
-
else
|
24
|
-
if options[:max_scan] && options[:max_scan] < count
|
25
|
-
options[:max_scan]
|
26
|
-
else
|
27
|
-
count
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
def unpage
|
34
|
-
clone.tap do |crit|
|
35
|
-
crit.options.delete :limit
|
36
|
-
crit.options.delete :skip
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'kaminari/models/mongoid_criteria_methods'
|
2
|
-
|
3
|
-
module Kaminari
|
4
|
-
module MongoidExtension
|
5
|
-
module Document
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
include Kaminari::ConfigurationMethods
|
8
|
-
|
9
|
-
included do
|
10
|
-
scope Kaminari.config.page_method_name, Proc.new {|num|
|
11
|
-
limit(default_per_page).offset(default_per_page * ((num = num.to_i - 1) < 0 ? 0 : num))
|
12
|
-
} do
|
13
|
-
include Kaminari::MongoidCriteriaMethods
|
14
|
-
include Kaminari::PageScopeMethods
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
module ClassMethods
|
19
|
-
def inherited(kls)
|
20
|
-
super
|
21
|
-
kls.send(:include, Kaminari::MongoidExtension::Document.dup)
|
22
|
-
end
|
23
|
-
end if Mongoid::VERSION < '5.0.0'
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,73 +0,0 @@
|
|
1
|
-
module Kaminari
|
2
|
-
module PageScopeMethods
|
3
|
-
# Specify the <tt>per_page</tt> value for the preceding <tt>page</tt> scope
|
4
|
-
# Model.page(3).per(10)
|
5
|
-
def per(num)
|
6
|
-
if (n = num.to_i) <= 0
|
7
|
-
self
|
8
|
-
elsif max_per_page && max_per_page < n
|
9
|
-
limit(max_per_page).offset(offset_value / limit_value * max_per_page)
|
10
|
-
else
|
11
|
-
limit(n).offset(offset_value / limit_value * n)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def padding(num)
|
16
|
-
@_padding = num
|
17
|
-
offset(offset_value + num.to_i)
|
18
|
-
end
|
19
|
-
|
20
|
-
# Total number of pages
|
21
|
-
def total_pages
|
22
|
-
count_without_padding = total_count
|
23
|
-
count_without_padding -= @_padding if defined?(@_padding) && @_padding
|
24
|
-
count_without_padding = 0 if count_without_padding < 0
|
25
|
-
|
26
|
-
total_pages_count = (count_without_padding.to_f / limit_value).ceil
|
27
|
-
if max_pages.present? && max_pages < total_pages_count
|
28
|
-
max_pages
|
29
|
-
else
|
30
|
-
total_pages_count
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def num_pages
|
35
|
-
ActiveSupport::Deprecation.warn 'num_pages is deprecated and will be removed in Kaminari 1.0. Please use total_pages instead.'
|
36
|
-
total_pages
|
37
|
-
end
|
38
|
-
|
39
|
-
# Current page number
|
40
|
-
def current_page
|
41
|
-
offset_without_padding = offset_value
|
42
|
-
offset_without_padding -= @_padding if defined?(@_padding) && @_padding
|
43
|
-
offset_without_padding = 0 if offset_without_padding < 0
|
44
|
-
|
45
|
-
(offset_without_padding / limit_value) + 1
|
46
|
-
end
|
47
|
-
|
48
|
-
# Next page number in the collection
|
49
|
-
def next_page
|
50
|
-
current_page + 1 unless last_page?
|
51
|
-
end
|
52
|
-
|
53
|
-
# Previous page number in the collection
|
54
|
-
def prev_page
|
55
|
-
current_page - 1 unless first_page?
|
56
|
-
end
|
57
|
-
|
58
|
-
# First page of the collection?
|
59
|
-
def first_page?
|
60
|
-
current_page == 1
|
61
|
-
end
|
62
|
-
|
63
|
-
# Last page of the collection?
|
64
|
-
def last_page?
|
65
|
-
current_page >= total_pages
|
66
|
-
end
|
67
|
-
|
68
|
-
# Out of range of the collection?
|
69
|
-
def out_of_range?
|
70
|
-
current_page > total_pages
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Kaminari
|
2
|
-
module PluckyCriteriaMethods
|
3
|
-
include Kaminari::PageScopeMethods
|
4
|
-
|
5
|
-
delegate :default_per_page, :max_per_page, :max_pages, :to => :model
|
6
|
-
|
7
|
-
def entry_name
|
8
|
-
model.model_name.human.downcase
|
9
|
-
end
|
10
|
-
|
11
|
-
def limit_value #:nodoc:
|
12
|
-
options[:limit]
|
13
|
-
end
|
14
|
-
|
15
|
-
def offset_value #:nodoc:
|
16
|
-
options[:skip]
|
17
|
-
end
|
18
|
-
|
19
|
-
def total_count #:nodoc:
|
20
|
-
count
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/lib/kaminari/railtie.rb
DELETED
data/lib/kaminari/sinatra.rb
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
require 'sinatra/base'
|
2
|
-
require 'kaminari'
|
3
|
-
require 'kaminari/helpers/sinatra_helpers'
|
4
|
-
|
5
|
-
ActiveSupport::Deprecation.warn 'Kaminari Sinatra support has been extracted to a separate gem, and will be removed in the next 1.0 release. Please bundle kaminari-sinatra gem.'
|
6
|
-
|
7
|
-
Kaminari::Hooks.init
|
data/spec/config/config_spec.rb
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Kaminari::Configuration do
|
4
|
-
subject { Kaminari.config }
|
5
|
-
describe 'default_per_page' do
|
6
|
-
context 'by default' do
|
7
|
-
its(:default_per_page) { should == 25 }
|
8
|
-
end
|
9
|
-
context 'configured via config block' do
|
10
|
-
before do
|
11
|
-
Kaminari.configure {|c| c.default_per_page = 17}
|
12
|
-
end
|
13
|
-
its(:default_per_page) { should == 17 }
|
14
|
-
after do
|
15
|
-
Kaminari.configure {|c| c.default_per_page = 25}
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe 'max_per_page' do
|
21
|
-
context 'by default' do
|
22
|
-
its(:max_per_page) { should == nil }
|
23
|
-
end
|
24
|
-
context 'configure via config block' do
|
25
|
-
before do
|
26
|
-
Kaminari.configure {|c| c.max_per_page = 100}
|
27
|
-
end
|
28
|
-
its(:max_per_page) { should == 100 }
|
29
|
-
after do
|
30
|
-
Kaminari.configure {|c| c.max_per_page = nil}
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe 'window' do
|
36
|
-
context 'by default' do
|
37
|
-
its(:window) { should == 4 }
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe 'outer_window' do
|
42
|
-
context 'by default' do
|
43
|
-
its(:outer_window) { should == 0 }
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe 'left' do
|
48
|
-
context 'by default' do
|
49
|
-
its(:left) { should == 0 }
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe 'right' do
|
54
|
-
context 'by default' do
|
55
|
-
its(:right) { should == 0 }
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe 'param_name' do
|
60
|
-
context 'by default' do
|
61
|
-
its(:param_name) { should == :page }
|
62
|
-
end
|
63
|
-
|
64
|
-
context 'configured via config block' do
|
65
|
-
before do
|
66
|
-
Kaminari.configure {|c| c.param_name = lambda { :test } }
|
67
|
-
end
|
68
|
-
|
69
|
-
its(:param_name) { should == :test }
|
70
|
-
|
71
|
-
after do
|
72
|
-
Kaminari.configure {|c| c.param_name = :page }
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe 'max_pages' do
|
78
|
-
context 'by default' do
|
79
|
-
its(:max_pages) { should == nil }
|
80
|
-
end
|
81
|
-
context 'configure via config block' do
|
82
|
-
before do
|
83
|
-
Kaminari.configure {|c| c.max_pages = 5}
|
84
|
-
end
|
85
|
-
its(:max_pages) { should == 5 }
|
86
|
-
after do
|
87
|
-
Kaminari.configure {|c| c.max_pages = nil}
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
# models
|
2
|
-
class User < ActiveRecord::Base
|
3
|
-
has_many :authorships
|
4
|
-
has_many :readerships
|
5
|
-
has_many :books_authored, :through => :authorships, :source => :book
|
6
|
-
has_many :books_read, :through => :readerships, :source => :book
|
7
|
-
has_many :addresses, :class_name => 'User::Address'
|
8
|
-
|
9
|
-
def readers
|
10
|
-
User.joins(:books_read => :authors).where(:authors_books => {:id => self})
|
11
|
-
end
|
12
|
-
|
13
|
-
scope :by_name, lambda { order(:name) }
|
14
|
-
scope :by_read_count, lambda {
|
15
|
-
cols = if connection.adapter_name == "PostgreSQL"
|
16
|
-
column_names.map { |column| %{"users"."#{column}"} }.join(", ")
|
17
|
-
else
|
18
|
-
'"users"."id"'
|
19
|
-
end
|
20
|
-
group(cols).select("count(readerships.id) AS read_count, #{cols}").order('read_count DESC')
|
21
|
-
}
|
22
|
-
end
|
23
|
-
class Authorship < ActiveRecord::Base
|
24
|
-
belongs_to :user
|
25
|
-
belongs_to :book
|
26
|
-
end
|
27
|
-
class Readership < ActiveRecord::Base
|
28
|
-
belongs_to :user
|
29
|
-
belongs_to :book
|
30
|
-
end
|
31
|
-
class Book < ActiveRecord::Base
|
32
|
-
has_many :authorships
|
33
|
-
has_many :readerships
|
34
|
-
has_many :authors, :through => :authorships, :source => :user
|
35
|
-
has_many :readers, :through => :readerships, :source => :user
|
36
|
-
end
|
37
|
-
# a model that is a descendant of AR::Base but doesn't directly inherit AR::Base
|
38
|
-
class Admin < User
|
39
|
-
end
|
40
|
-
# a model with namespace
|
41
|
-
class User::Address < ActiveRecord::Base
|
42
|
-
belongs_to :user
|
43
|
-
end
|
44
|
-
|
45
|
-
# a class that uses abstract class
|
46
|
-
class Product < ActiveRecord::Base
|
47
|
-
self.abstract_class = true
|
48
|
-
end
|
49
|
-
class Device < Product
|
50
|
-
end
|
51
|
-
|
52
|
-
#migrations
|
53
|
-
class CreateAllTables < ActiveRecord::Migration
|
54
|
-
def self.up
|
55
|
-
create_table(:gem_defined_models) { |t| t.string :name; t.integer :age }
|
56
|
-
create_table(:users) {|t| t.string :name; t.integer :age}
|
57
|
-
create_table(:books) {|t| t.string :title}
|
58
|
-
create_table(:readerships) {|t| t.integer :user_id; t.integer :book_id }
|
59
|
-
create_table(:authorships) {|t| t.integer :user_id; t.integer :book_id }
|
60
|
-
create_table(:user_addresses) {|t| t.string :street; t.integer :user_id }
|
61
|
-
create_table(:devices) {|t| t.string :name; t.integer :age}
|
62
|
-
end
|
63
|
-
end
|
64
|
-
ActiveRecord::Migration.verbose = false
|
65
|
-
CreateAllTables.up
|
@@ -1 +0,0 @@
|
|
1
|
-
DataMapper.setup(:default, 'sqlite::memory:')
|
@@ -1,27 +0,0 @@
|
|
1
|
-
class User
|
2
|
-
include ::DataMapper::Resource
|
3
|
-
|
4
|
-
property :id, Serial
|
5
|
-
property :name, String, :required => true
|
6
|
-
property :age, Integer
|
7
|
-
|
8
|
-
has n, :projects, :through => Resource
|
9
|
-
end
|
10
|
-
|
11
|
-
class User::Address
|
12
|
-
include ::DataMapper::Resource
|
13
|
-
|
14
|
-
property :id, Serial
|
15
|
-
end
|
16
|
-
|
17
|
-
class Project
|
18
|
-
include ::DataMapper::Resource
|
19
|
-
|
20
|
-
property :id, Serial
|
21
|
-
property :name, String, :required => true
|
22
|
-
|
23
|
-
has n, :users, :through => Resource
|
24
|
-
end
|
25
|
-
|
26
|
-
DataMapper.finalize
|
27
|
-
DataMapper.auto_migrate!
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# Ensure we use 'syck' instead of 'psych' in 1.9.2
|
2
|
-
# RubyGems >= 1.5.0 uses 'psych' on 1.9.2, but
|
3
|
-
# Psych does not yet support YAML 1.1 merge keys.
|
4
|
-
# Merge keys is often used in mongoid.yml
|
5
|
-
# See: http://redmine.ruby-lang.org/issues/show/4300
|
6
|
-
require 'mongoid/version'
|
7
|
-
|
8
|
-
if RUBY_VERSION >= '1.9.2' && RUBY_VERSION < '2.2.0'
|
9
|
-
YAML::ENGINE.yamler = 'syck'
|
10
|
-
end
|
11
|
-
|
12
|
-
Mongoid.configure do |config|
|
13
|
-
if Mongoid::VERSION >= '5.0.0'
|
14
|
-
config.connect_to 'kaminari_test'
|
15
|
-
elsif Mongoid::VERSION > '3.0.0'
|
16
|
-
config.sessions = {:default => {:hosts => ['0.0.0.0:27017'], :database => 'kaminari_test'}}
|
17
|
-
else
|
18
|
-
config.master = Mongo::Connection.new.db('kaminari_test')
|
19
|
-
end
|
20
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
class User
|
2
|
-
include ::Mongoid::Document
|
3
|
-
if Mongoid::VERSION >= '4.0.0'
|
4
|
-
include Mongoid::Attributes::Dynamic
|
5
|
-
end
|
6
|
-
|
7
|
-
field :name, :type => String
|
8
|
-
field :age, :type => Integer
|
9
|
-
end
|
10
|
-
|
11
|
-
class User::Address
|
12
|
-
include ::Mongoid::Document
|
13
|
-
end
|
14
|
-
|
15
|
-
class Product
|
16
|
-
include ::Mongoid::Document
|
17
|
-
end
|
18
|
-
|
19
|
-
class Device < Product
|
20
|
-
paginates_per 100
|
21
|
-
end
|
22
|
-
|
23
|
-
class Android < Device
|
24
|
-
paginates_per 200
|
25
|
-
end
|
26
|
-
|
27
|
-
class MongoMongoidExtensionDeveloper
|
28
|
-
include ::Mongoid::Document
|
29
|
-
field :salary, :type => Integer
|
30
|
-
embeds_many :frameworks
|
31
|
-
end
|
32
|
-
|
33
|
-
class Framework
|
34
|
-
include ::Mongoid::Document
|
35
|
-
field :name, :type => String
|
36
|
-
field :language, :type => String
|
37
|
-
embedded_in :mongo_mongoid_extension_developer
|
38
|
-
end
|
data/spec/fake_app/rails_app.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
# require 'rails/all'
|
2
|
-
require 'action_controller/railtie'
|
3
|
-
require 'action_view/railtie'
|
4
|
-
|
5
|
-
require 'fake_app/active_record/config' if defined? ActiveRecord
|
6
|
-
require 'fake_app/data_mapper/config' if defined? DataMapper
|
7
|
-
require 'fake_app/mongoid/config' if defined? Mongoid
|
8
|
-
require 'fake_app/mongo_mapper/config' if defined? MongoMapper
|
9
|
-
# config
|
10
|
-
app = Class.new(Rails::Application)
|
11
|
-
app.config.secret_token = '3b7cd727ee24e8444053437c36cc66c4'
|
12
|
-
app.config.session_store :cookie_store, :key => '_myapp_session'
|
13
|
-
app.config.active_support.deprecation = :log
|
14
|
-
app.config.eager_load = false
|
15
|
-
# Rais.root
|
16
|
-
app.config.root = File.dirname(__FILE__)
|
17
|
-
Rails.backtrace_cleaner.remove_silencers!
|
18
|
-
app.initialize!
|
19
|
-
|
20
|
-
# routes
|
21
|
-
app.routes.draw do
|
22
|
-
resources :users
|
23
|
-
end
|
24
|
-
|
25
|
-
#models
|
26
|
-
require 'fake_app/active_record/models' if defined? ActiveRecord
|
27
|
-
require 'fake_app/data_mapper/models' if defined? DataMapper
|
28
|
-
require 'fake_app/mongoid/models' if defined? Mongoid
|
29
|
-
require 'fake_app/mongo_mapper/models' if defined? MongoMapper
|
30
|
-
|
31
|
-
# controllers
|
32
|
-
class ApplicationController < ActionController::Base; end
|
33
|
-
class UsersController < ApplicationController
|
34
|
-
def index
|
35
|
-
@users = User.page params[:page]
|
36
|
-
render :inline => <<-ERB
|
37
|
-
<%= @users.map(&:name).join("\n") %>
|
38
|
-
<%= paginate @users %>
|
39
|
-
ERB
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
if defined? ActiveRecord
|
44
|
-
class AddressesController < ApplicationController
|
45
|
-
def index
|
46
|
-
@addresses = User::Address.page params[:page]
|
47
|
-
render :inline => <<-ERB
|
48
|
-
<%= @addresses.map(&:street).join("\n") %>
|
49
|
-
<%= paginate @addresses %>
|
50
|
-
ERB
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
# helpers
|
56
|
-
Object.const_set(:ApplicationHelper, Module.new)
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'fake_app/active_record/config' if defined? ActiveRecord
|
2
|
-
require 'fake_app/data_mapper/config' if defined? DataMapper
|
3
|
-
require 'fake_app/mongoid/config' if defined? Mongoid
|
4
|
-
require 'fake_app/mongo_mapper/config' if defined? MongoMapper
|
5
|
-
|
6
|
-
#models
|
7
|
-
require 'fake_app/active_record/models' if defined? ActiveRecord
|
8
|
-
require 'fake_app/data_mapper/models' if defined? DataMapper
|
9
|
-
require 'fake_app/mongoid/models' if defined? Mongoid
|
10
|
-
require 'fake_app/mongo_mapper/models' if defined? MongoMapper
|
11
|
-
|
12
|
-
class SinatraApp < Sinatra::Base
|
13
|
-
register Kaminari::Helpers::SinatraHelpers
|
14
|
-
|
15
|
-
get '/users' do
|
16
|
-
@users = User.page params[:page]
|
17
|
-
erb <<-ERB
|
18
|
-
<%= @users.map(&:name).join("\n") %>
|
19
|
-
<%= paginate @users %>
|
20
|
-
ERB
|
21
|
-
end
|
22
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
<b><%= current_page %></b>
|
@@ -1 +0,0 @@
|
|
1
|
-
<li class="bootstrap-page-link"><%= link_to page, url %></li>
|