Sha256: 8106f1d93213789078496ec19aec98973aac6ec7ca4e61c735af37deaca54db1

Contents?: true

Size: 1.39 KB

Versions: 12

Compression:

Stored size: 1.39 KB

Contents

module Shamu
  module JsonApi
    module Rails

      # Pagination information gathered from the request.
      class Pagination
        include Attributes
        include Attributes::Assignment
        include Attributes::Validation

        # ============================================================================
        # @!group Attributes
        #

        # @!attribute
        # @return [Symbol] the request parameter the pagination was read from. Default `:page`.
        attribute :param, default: :page

        # @!attribute
        # @return [Integer] the page number.
        attribute :number, coerce: :to_i

        # @!attribute
        # @return [Integer] the size of each page.
        attribute :size, coerce: :to_i

        # @!attribute
        # @return [Integer] offset into the list.
        attribute :offset, coerce: :to_i

        # @!attribute
        # @return [Integer] limit the total number of results.
        attribute :limit, coerce: :to_i

        # @!attribute
        # @return [String] opaque cursor value
        attribute :cursor, coerce: :to_i

        #
        # @!endgroup Attributes

        validate :only_one_kind_of_paging

        private

          def only_one_kind_of_paging
            kinds = [ number, offset, cursor ].compact
            errors.add :base, :only_one_kind_of_paging if kinds.count > 2 || ( size && limit )
          end

      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
shamu-0.0.24 lib/shamu/json_api/rails/pagination.rb
shamu-0.0.21 lib/shamu/json_api/rails/pagination.rb
shamu-0.0.20 lib/shamu/json_api/rails/pagination.rb
shamu-0.0.19 lib/shamu/json_api/rails/pagination.rb
shamu-0.0.18 lib/shamu/json_api/rails/pagination.rb
shamu-0.0.17 lib/shamu/json_api/rails/pagination.rb
shamu-0.0.15 lib/shamu/json_api/rails/pagination.rb
shamu-0.0.14 lib/shamu/json_api/rails/pagination.rb
shamu-0.0.13 lib/shamu/json_api/rails/pagination.rb
shamu-0.0.11 lib/shamu/json_api/rails/pagination.rb
shamu-0.0.9 lib/shamu/json_api/rails/pagination.rb
shamu-0.0.8 lib/shamu/json_api/rails/pagination.rb