Sha256: d66397752f49e3575e49adb604d8fe87d64524a01d09e5d7cabbc2bea465b030
Contents?: true
Size: 717 Bytes
Versions: 7
Compression:
Stored size: 717 Bytes
Contents
# rubocop:disable Style/Not class Simple::SQL::Connection::Scope # Set pagination def paginate(per:, page:) raise ArgumentError, "per must be > 0" unless per > 0 raise ArgumentError, "page must be > 0" unless page > 0 duplicate.send(:paginate!, per: per, page: page) end # Is this a paginated scope? def paginated? not @per.nil? end private def paginate!(per:, page:) @per = per @page = page self end def apply_pagination(sql, pagination:) return sql unless pagination == :auto && @per && @page raise ArgumentError, "You cannot mix 'paginate' and 'offset'/'limit'" if @offset || @limit "#{sql} LIMIT #{@per} OFFSET #{(@page - 1) * @per}" end end
Version data entries
7 entries across 7 versions & 1 rubygems