Sha256: 7b0f6a226b7716f4c282bef1f46747dbe63a0fa8406402c9d85b587f86a4c3d0

Contents?: true

Size: 952 Bytes

Versions: 10

Compression:

Stored size: 952 Bytes

Contents

# frozen_string_literal: true
require 'drillbit/parameters/page'

module  Drillbit
module  Resource
module  Processors
class   Paging
  attr_accessor :resource,
                :parameters

  # rubocop:disable Style/OptionHash
  def initialize(resource, parameters = {})
    self.resource   = resource
    self.parameters = Parameters::Page.new(parameters['page'] || {})
  end
  # rubocop:enable Style/OptionHash

  def self.processed(*attrs)
    new(*attrs).processed
  end

  def self.meta(*attrs)
    new(*attrs).meta
  end

  def processed
    return resource unless parameters.present?

    resource.page(parameters.page_number).
             per(parameters.per_page)
  end

  def meta
    return {} unless parameters.present?

    {
      'total-pages'   => resource.total_pages,
      'current-page'  => resource.current_page,
      'previous-page' => resource.prev_page,
      'next-page'     => resource.next_page,
    }
  end
end
end
end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
drillbit-2.2.2 lib/drillbit/resource/processors/paging.rb
drillbit-2.2.1 lib/drillbit/resource/processors/paging.rb
drillbit-2.2.0 lib/drillbit/resource/processors/paging.rb
drillbit-2.1.0 lib/drillbit/resource/processors/paging.rb
drillbit-2.0.1 lib/drillbit/resource/processors/paging.rb
drillbit-2.0.0 lib/drillbit/resource/processors/paging.rb
drillbit-1.1.0 lib/drillbit/resource/processors/paging.rb
drillbit-1.0.1 lib/drillbit/resource/processors/paging.rb
drillbit-1.0.0 lib/drillbit/resource/processors/paging.rb
drillbit-0.0.1 lib/drillbit/resource/processors/paging.rb