Sha256: 84697255d9e5ec44933e1ced6e94d88aa77e2f142c7993c709640fac607cb20f

Contents?: true

Size: 1.02 KB

Versions: 54

Compression:

Stored size: 1.02 KB

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
        when :link
          LHS::Pagination::Link
        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).present? ||
          raw.dig(*limit_key(:body)).present?
        )
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
lhs-26.2.0 lib/lhs/concerns/record/pagination.rb
lhs-26.1.0 lib/lhs/concerns/record/pagination.rb
lhs-26.0.1 lib/lhs/concerns/record/pagination.rb
lhs-26.0.0 lib/lhs/concerns/record/pagination.rb
lhs-25.2.0 lib/lhs/concerns/record/pagination.rb
lhs-25.0.4 lib/lhs/concerns/record/pagination.rb
lhs-25.0.3 lib/lhs/concerns/record/pagination.rb
lhs-25.0.2 lib/lhs/concerns/record/pagination.rb
lhs-25.0.1 lib/lhs/concerns/record/pagination.rb
lhs-25.0.0 lib/lhs/concerns/record/pagination.rb
lhs-24.1.2 lib/lhs/concerns/record/pagination.rb
lhs-24.1.1 lib/lhs/concerns/record/pagination.rb
lhs-24.1.0 lib/lhs/concerns/record/pagination.rb
lhs-24.1.0.pre.2 lib/lhs/concerns/record/pagination.rb
lhs-24.1.0.pre.1 lib/lhs/concerns/record/pagination.rb
lhs-24.0.0 lib/lhs/concerns/record/pagination.rb
lhs-23.0.2 lib/lhs/concerns/record/pagination.rb
lhs-23.0.1 lib/lhs/concerns/record/pagination.rb
lhs-23.0.0 lib/lhs/concerns/record/pagination.rb
lhs-22.1.1.pre lib/lhs/concerns/record/pagination.rb