Sha256: 09325deb58117534c31f399621765a4318a8cb840a05ea8a9f241dd08a6d7002
Contents?: true
Size: 986 Bytes
Versions: 1
Compression:
Stored size: 986 Bytes
Contents
module Munson module Paginator class OffsetPaginator def initialize(options={}) @max_limit = options[:max] @default_limit = options[:default] end def set(opts={}) limit(opts[:limit]) if opts[:limit] offset(opts[:offset]) if opts[:offset] end def to_params { page: { limit: @limit || @default_limit || 10, offset: @offset }.select { |_, value| !value.nil? } } end private # Set limit of resources per page # # @param [Fixnum] num number of resources per page def limit(num) if @max_limit && num > @max_limit @limit = @max_limit else @limit = num end end # Set offset # # @param [Fixnum] num pages to offset def offset(num) @offset = num end end end end Munson.register_paginator(:offset, Munson::Paginator::OffsetPaginator)
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
munson-0.2.0 | lib/munson/paginator/offset_paginator.rb |