Sha256: 9c8f90b0ee8a79ad5cd379ac0e7fc71c1276fe9e6289231d48996eddcea4a13b

Contents?: true

Size: 913 Bytes

Versions: 21

Compression:

Stored size: 913 Bytes

Contents

# frozen_string_literal: true

require 'active_support'

class LHS::Record

  module Pagination
    extend ActiveSupport::Concern
    # Kaminari-Interface
    delegate :current_page, :first_page, :last_page, :prev_page, :next_page, :limit_value, :total_pages, to: :_pagination

    def paginated?(raw = nil)
      self.class.paginated?(raw || _raw)
    end

    def _pagination
      self.class.pagination(_data)
    end

    module ClassMethods
      def pagination_class
        case pagination_strategy.to_sym
        when :page
          LHS::Pagination::Page
        when :start
          LHS::Pagination::Start
        else
          LHS::Pagination::Offset
        end
      end

      def pagination(data)
        pagination_class.new(data)
      end

      # Checks if given raw is paginated or not
      def paginated?(raw)
        !!(raw.is_a?(Hash) && raw.dig(*total_key))
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
lhs-19.5.0 lib/lhs/concerns/record/pagination.rb
lhs-19.5.0.pre.wherehref.1 lib/lhs/concerns/record/pagination.rb
lhs-19.4.1 lib/lhs/concerns/record/pagination.rb
lhs-19.4.0 lib/lhs/concerns/record/pagination.rb
lhs-19.3.1 lib/lhs/concerns/record/pagination.rb
lhs-19.3.0 lib/lhs/concerns/record/pagination.rb
lhs-19.2.0 lib/lhs/concerns/record/pagination.rb
lhs-19.1.0 lib/lhs/concerns/record/pagination.rb
lhs-19.0.2 lib/lhs/concerns/record/pagination.rb
lhs-19.0.1 lib/lhs/concerns/record/pagination.rb
lhs-19.0.0 lib/lhs/concerns/record/pagination.rb
lhs-19.0.0.pre.endpoint.1 lib/lhs/concerns/record/pagination.rb
lhs-18.0.3 lib/lhs/concerns/record/pagination.rb
lhs-18.0.2 lib/lhs/concerns/record/pagination.rb
lhs-18.0.1 lib/lhs/concerns/record/pagination.rb
lhs-18.0.0 lib/lhs/concerns/record/pagination.rb
lhs-17.0.1 lib/lhs/concerns/record/pagination.rb
lhs-17.0.1.pre1 lib/lhs/concerns/record/pagination.rb
lhs-18.0.0.pre.pre1 lib/lhs/concerns/record/pagination.rb
lhs-17.0.0 lib/lhs/concerns/record/pagination.rb