Sha256: 23f6c649cf16f63cf7166dcb8f3e79ef073af6258e732429a95594bee1b7a57b
Contents?: true
Size: 840 Bytes
Versions: 1
Compression:
Stored size: 840 Bytes
Contents
module Pageable module ActiveRecord module Base extend ActiveSupport::Concern module ClassMethods def inherited(subclass) subclass.class_eval do if superclass == ::ActiveRecord::Base scope :page, ->(number) { limit(default_per_page).offset(default_per_page * ([number.to_i, 1].max - 1)) } do include Pageable::ActiveRecord::Relation end end end super end def default_per_page(value=nil) unless value.nil? value = [value.to_i, 1].max @default_per_page = value end defined?(@default_per_page).nil? ? Rails.application.config.pagination.default_per_page : @default_per_page end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pageable-2.1.0 | lib/pageable/active_record/base.rb |