Permalink
Browse files

Simplify page_entries_info by adding entry_name interface to each ORM

  • Loading branch information...
yuki24 committed Mar 16, 2014
1 parent defc7ba commit 507fb73b09475a0efbd99d0398bf4a3c9632ca18
@@ -86,17 +86,7 @@ def link_to_next_page(scope, name, options = {}, &block)
# <%= page_entries_info @posts, :entry_name => 'item' %>
# #-> Displaying items 6 - 10 of 26 in total
def page_entries_info(collection, options = {})
entry_name = if options[:entry_name]
options[:entry_name]
elsif collection.is_a?(::Kaminari::PaginatableArray)
'entry'
else
if collection.respond_to? :model # DataMapper
collection.model.model_name.human.downcase
else # AR
collection.model_name.human.downcase
end
end
entry_name = options[:entry_name] || collection.entry_name
entry_name = entry_name.pluralize unless collection.total_count == 1
if collection.total_pages < 2
@@ -8,6 +8,10 @@ def count(column_name = nil, options = {}) #:nodoc:
end
end
def entry_name
model_name.human.downcase
end
def total_count(column_name = :all, options = {}) #:nodoc:
# #count overrides the #select which could include generated columns referenced in #order, so skip #order here, where it's irrelevant to the result anyway
@total_count ||= begin
@@ -24,6 +24,10 @@ def initialize(original_array = [], options = {})
end
end
def entry_name
"entry"
end
# items at the specified "page"
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{Kaminari.config.page_method_name}(num = 1)
@@ -1,5 +1,9 @@
module Kaminari
module DataMapperCollectionMethods
def entry_name
model.model_name.human.downcase
end
def limit_value #:nodoc:
query.options[:limit] || 0
end
@@ -1,5 +1,9 @@
module Kaminari
module MongoidCriteriaMethods
def entry_name
model_name.human.downcase
end
def limit_value #:nodoc:
options[:limit]
end
@@ -4,6 +4,10 @@ module PluckyCriteriaMethods
delegate :default_per_page, :max_per_page, :max_pages, :to => :model
def entry_name
model.model_name.human.downcase
end
def limit_value #:nodoc:
options[:limit]
end

0 comments on commit 507fb73

Please sign in to comment.