Class: Graphiti::Delegates::Pagination

Inherits:
Object
  • Object
show all
Defined in:
lib/graphiti/delegates/pagination.rb

Instance Method Summary collapse

Constructor Details

#initialize(proxy) ⇒ Pagination

Returns a new instance of Pagination.



4
5
6
# File 'lib/graphiti/delegates/pagination.rb', line 4

def initialize(proxy)
  @proxy = proxy
end

Instance Method Details

#has_next_page?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/graphiti/delegates/pagination.rb', line 22

def has_next_page?
  current_page != last_page && last_page.present?
end

#has_previous_page?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
# File 'lib/graphiti/delegates/pagination.rb', line 26

def has_previous_page?
  current_page != 1 ||
    !!pagination_params.try(:[], :page).try(:[], :after) ||
    !!pagination_params.try(:[], :page).try(:[], :offset)
end


12
13
14
15
16
17
18
19
20
# File 'lib/graphiti/delegates/pagination.rb', line 12

def links
  @links ||= {}.tap do |links|
    links[:self] = pagination_link(current_page)
    links[:first] = pagination_link(1)
    links[:last] = pagination_link(last_page)
    links[:prev] = pagination_link(current_page - 1) if has_previous_page?
    links[:next] = pagination_link(current_page + 1) if has_next_page?
  end.select { |k, v| !v.nil? }
end

#links?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/graphiti/delegates/pagination.rb', line 8

def links?
  @proxy.query.pagination_links? && @proxy.data.present?
end