Created
June 15, 2011 17:21
-
-
Save kusakari/1027584 to your computer and use it in GitHub Desktop.
kaminariでページネートオブジェクトだけが欲しいときに
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
module Kaminari | |
class SimplePaginatable | |
DEFAULTS = { | |
:total_count => 0, | |
} | |
include Kaminari::ConfigurationMethods::ClassMethods | |
attr_internal_accessor :limit_value, :offset_value | |
def initialize(options, limit_val = default_per_page, offset_val = 0) #:nodoc: | |
@_options, @_limit_value, @_offset_value = options, limit_val, offset_val | |
end | |
def page(num = 1) | |
offset(limit_value * ([num.to_i, 1].max - 1)) | |
end | |
def limit(num) | |
self.class.new @_options, num, offset_value | |
end | |
def total_count | |
@_options[:total_count] | |
end | |
def offset(num) | |
obj = self.class.new @_options, limit_value, num | |
class << obj | |
include Kaminari::PageScopeMethods | |
end | |
obj | |
end | |
end | |
def self.create_pagination(options) | |
SimplePaginatable.new SimplePaginatable::DEFAULTS.merge(options) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment