Sha256: 25cd145e6a9ee51a04e21cf7c39bd0fabf38b4fbb41b3a2b718ed3579f42c345

Contents?: true

Size: 752 Bytes

Versions: 8

Compression:

Stored size: 752 Bytes

Contents

module JsonapiCompliable
  class Scope::Paginate < Scope::Base
    MAX_PAGE_SIZE = 1_000

    def apply
      if size > MAX_PAGE_SIZE
        raise JsonapiCompliable::Errors::UnsupportedPageSize
          .new(size, MAX_PAGE_SIZE)
      else
        super
      end
    end

    def custom_scope
      dsl.pagination
    end

    def apply_standard_scope
      @scope.page(number).per(size)
    end

    def apply_custom_scope
      custom_scope.call(@scope, number, size)
    end

    private

    def page_param
      @page_param ||= (params[:page] || {})
    end

    def number
      (page_param[:number] || controller.default_page_number).to_i
    end

    def size
      (page_param[:size] || controller.default_page_size).to_i
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
jsonapi_compliable-0.4.0 lib/jsonapi_compliable/scope/paginate.rb
jsonapi_compliable-0.3.10 lib/jsonapi_compliable/scope/paginate.rb
jsonapi_compliable-0.3.9 lib/jsonapi_compliable/scope/paginate.rb
jsonapi_compliable-0.3.8 lib/jsonapi_compliable/scope/paginate.rb
jsonapi_compliable-0.3.7 lib/jsonapi_compliable/scope/paginate.rb
jsonapi_compliable-0.3.6 lib/jsonapi_compliable/scope/paginate.rb
jsonapi_compliable-0.3.5 lib/jsonapi_compliable/scope/paginate.rb
jsonapi_compliable-0.3.4 lib/jsonapi_compliable/scope/paginate.rb