Sha256: 605d57eaa4e7e1d153bb12cf9b1d039a8d6ce363603527904f1f83d43994f56b

Contents?: true

Size: 882 Bytes

Versions: 13

Compression:

Stored size: 882 Bytes

Contents

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

13 entries across 13 versions & 1 rubygems

Version Path
lhs-16.1.5 lib/lhs/concerns/record/pagination.rb
lhs-16.1.4 lib/lhs/concerns/record/pagination.rb
lhs-16.1.3 lib/lhs/concerns/record/pagination.rb
lhs-16.1.2 lib/lhs/concerns/record/pagination.rb
lhs-16.1.1 lib/lhs/concerns/record/pagination.rb
lhs-16.1.0 lib/lhs/concerns/record/pagination.rb
lhs-16.0.1 lib/lhs/concerns/record/pagination.rb
lhs-16.0.0 lib/lhs/concerns/record/pagination.rb
lhs-15.7.0 lib/lhs/concerns/record/pagination.rb
lhs-15.6.1 lib/lhs/concerns/record/pagination.rb
lhs-15.6.0 lib/lhs/concerns/record/pagination.rb
lhs-15.5.1 lib/lhs/concerns/record/pagination.rb
lhs-15.5.0 lib/lhs/concerns/record/pagination.rb