Sha256: 13f1f058bfb8c7225ebad05c6777ce7fe30ba06333d5efb032fcc166662cf474
Contents?: true
Size: 1.11 KB
Versions: 1
Compression:
Stored size: 1.11 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] || Pagers.config.length padding = options[:padding] || Pagers.config.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.1.0 | lib/pagers/active_record/base.rb |