9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/pagers/extensions/active_record/base.rb', line 9
def inherited(subclass)
subclass.class_eval do
if superclass == ::ActiveRecord::Base
scope :page, ->(number, options={}) {
padding = (options[:padding] || Pagers.configuration.padding)
length = (options[:length] || Pagers.configuration.length)
current_page = [number.to_i, 1].max
limit = length
offset = ((length * (current_page - 1)) + padding)
values = Module.new do
define_method :padding do
padding
end
define_method :page_length do
length
end
define_method :current_page do
current_page
end
end
limit(limit).offset(offset).extending(
Pagers::Extensions::ActiveRecord::Relation,
values
)
}
end
end
super
end
|