Module: DHS::Record::Pagination::ClassMethods

Defined in:
lib/dhs/concerns/record/pagination.rb

Instance Method Summary collapse

Instance Method Details

#paginated?(raw) ⇒ Boolean

Checks if given raw is paginated or not

Returns:

  • (Boolean)


47
48
49
50
51
52
53
# File 'lib/dhs/concerns/record/pagination.rb', line 47

def paginated?(raw)
  raw.is_a?(Hash) && (
    raw.dig(*total_key).present? ||
    raw.dig(*limit_key(:body)).present? ||
    raw.dig(*pagination_key(:body)).present?
  )
end

#pagination(data) ⇒ Object



42
43
44
# File 'lib/dhs/concerns/record/pagination.rb', line 42

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

#pagination_classObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/dhs/concerns/record/pagination.rb', line 21

def pagination_class
  case pagination_strategy.to_sym
  when :page
    DHS::Pagination::Page
  when :total_pages
    DHS::Pagination::TotalPages
  when :offset_page
    DHS::Pagination::OffsetPage
  when :start
    DHS::Pagination::Start
  when :link
    DHS::Pagination::Link
  when :next_offset
    DHS::Pagination::NextOffset
  when :next_parameter
    DHS::Pagination::NextParameter
  else
    DHS::Pagination::Offset
  end
end