Sha256: 700c6a5870b346d2ba0121cc058c7e352573d6093c6dfe4c786399a32b577991

Contents?: true

Size: 868 Bytes

Versions: 46

Compression:

Stored size: 868 Bytes

Contents

module Shipit
  module Api
    module Paginable
      extend ActiveSupport::Concern

      LINK = 'Link'.freeze

      included do
        class_attribute :max_page_size
        class_attribute :default_page_size
        class_attribute :default_order

        self.max_page_size = 100
        self.default_page_size = 30
        self.default_order = {id: :desc}.freeze
      end

      private

      def render_resources(resource, *)
        paginator = Shipit::Paginator.new(
          resource,
          self,
          order: default_order,
          max_page_size: max_page_size,
          default_page_size: default_page_size,
        )
        headers[LINK] = render_links(paginator.links)
        super(paginator.to_a)
      end

      def render_links(links)
        links.map { |rel, url| %(<#{url}>; rel="#{rel}") }.join(', ')
      end
    end
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
shipit-engine-0.31.0 app/controllers/concerns/shipit/api/paginable.rb
shipit-engine-0.30.0 app/controllers/concerns/shipit/api/paginable.rb
shipit-engine-0.29.0 app/controllers/concerns/shipit/api/paginable.rb
shipit-engine-0.28.1 app/controllers/concerns/shipit/api/paginable.rb
shipit-engine-0.28.0 app/controllers/concerns/shipit/api/paginable.rb
shipit-engine-0.27.1 app/controllers/concerns/shipit/api/paginable.rb
shipit-engine-0.27.0 app/controllers/concerns/shipit/api/paginable.rb
shipit-engine-0.26.0 app/controllers/concerns/shipit/api/paginable.rb
shipit-engine-0.25.1 app/controllers/concerns/shipit/api/paginable.rb
shipit-engine-0.25.0 app/controllers/concerns/shipit/api/paginable.rb
shipit-engine-0.24.0 app/controllers/concerns/shipit/api/paginable.rb
shipit-engine-0.23.1 app/controllers/concerns/shipit/api/paginable.rb
shipit-engine-0.23.0 app/controllers/concerns/shipit/api/paginable.rb
shipit-engine-0.22.0 app/controllers/concerns/shipit/api/paginable.rb
shipit-engine-0.21.0 app/controllers/concerns/shipit/api/paginable.rb
shipit-engine-0.20.1 app/controllers/concerns/shipit/api/paginable.rb
shipit-engine-0.20.0 app/controllers/concerns/shipit/api/paginable.rb
shipit-engine-0.19.0 app/controllers/concerns/shipit/api/paginable.rb
shipit-engine-0.18.1 app/controllers/concerns/shipit/api/paginable.rb
shipit-engine-0.18.0 app/controllers/concerns/shipit/api/paginable.rb