Sha256: e5d3663731ade5f333164dc181bd70c0806cdc0b673aa027f5149e2226c6cf53
Contents?: true
Size: 1.15 KB
Versions: 1
Compression:
Stored size: 1.15 KB
Contents
module Pagers module ActiveRecord module Base extend ActiveSupport::Concern module ClassMethods def inherited(subclass) subclass.class_eval do if superclass == ::ActiveRecord::Base scope :page, ->(number, options={}) { length = options[:length] || Rails.application.config.pagers[:length] padding = options[:padding] || Rails.application.config.pagers[:padding] current_page = [number.to_i, 1].max offset_value = (length * (current_page - 1)) + padding limit_value = length 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_value).offset(offset_value).extending(Pagers::ActiveRecord::Relation, values) } end end super end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pagers-3.0.3 | lib/pagers/active_record/base.rb |