Sha256: e985b941f82b0b2710841a700640aae39cab9e18ee32b4a738f3ecc774e07dfa
Contents?: true
Size: 1.31 KB
Versions: 8
Compression:
Stored size: 1.31 KB
Contents
module Shamu module Entities class ListScope # Include paging parsing and attributes. Adds the following attributes # to the list scope: # # ``` # class UsersListScope < Shamu::Entities::ListScope # include Shamu::Entities::ListScope::Paging # end # # scope = UsersListScope.coerce!( params ) # scope.page # => 1 # scope.per_page # => 25 # ``` module Paging # ============================================================================ # @!group Attributes # # @!attribute page # @return [Integer] the current page number. 1 based. # @!attribute per_page # @return [Integer] number of records per page. # @!attribute default_per_page # @return [Integer] default number of records per page if not provided. # # @!endgroup Attributes def self.included( base ) super base.attribute :page, coerce: :to_i base.attribute :per_page, coerce: :to_i, default: ->() { default_per_page } base.attribute :default_per_page, coerce: :to_i, serialize: false end # @return [Boolean] true if the scope is paged. def paged? !!page || !!per_page end end end end end
Version data entries
8 entries across 8 versions & 1 rubygems