forked from kaminari/kaminari
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'concern_refactor' of https://github.com/l15n/kaminari i…
…nto l15n-concern_refactor
- Loading branch information
Showing
7 changed files
with
84 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Kaminari | ||
module ActiveRecordRelationMethods | ||
extend ActiveSupport::Concern | ||
module InstanceMethods | ||
def pagination_count | ||
except(:offset, :limit).count | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Kaminari | ||
module ConfigurationMethods | ||
extend ActiveSupport::Concern | ||
module ClassMethods | ||
# Overrides the default per_page value per model | ||
# class Article < ActiveRecord::Base | ||
# paginates_per 10 | ||
# end | ||
def paginates_per(val) | ||
@_default_per_page = val | ||
end | ||
|
||
# This model's default per_page value | ||
# returns 25 unless explicitly overridden via <tt>paginates_per</tt> | ||
def default_per_page | ||
@_default_per_page || Kaminari::DEFAULT_PER_PAGE | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Kaminari | ||
module MongoidCriteriaMethods | ||
extend ActiveSupport::Concern | ||
module InstanceMethods | ||
def limit_value | ||
options[:limit] | ||
end | ||
def offset_value | ||
options[:skip] | ||
end | ||
def pagination_count | ||
count | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Kaminari | ||
module PageScopeMethods | ||
extend ActiveSupport::Concern | ||
module InstanceMethods | ||
# Specify the <tt>per_page</tt> value for the preceding <tt>page</tt> scope | ||
# Model.page(3).per(10) | ||
def per(num) | ||
if (n = num.to_i) <= 0 | ||
self | ||
else | ||
limit(n).offset(offset_value / limit_value * n) | ||
end | ||
end | ||
|
||
# Total number of pages | ||
def num_pages | ||
(pagination_count.to_f / limit_value).ceil | ||
end | ||
|
||
# Current page number | ||
def current_page | ||
(offset_value / limit_value) + 1 | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters