Class: ActiveShopifyGraphQL::Response::PageInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/active_shopify_graphql/response/page_info.rb

Overview

Holds pagination metadata returned from a Shopify GraphQL connection query. Provides methods for navigating between pages.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ PageInfo

Returns a new instance of PageInfo.



10
11
12
13
14
15
# File 'lib/active_shopify_graphql/response/page_info.rb', line 10

def initialize(data = {})
  @has_next_page = data["hasNextPage"] || false
  @has_previous_page = data["hasPreviousPage"] || false
  @start_cursor = data["startCursor"]
  @end_cursor = data["endCursor"]
end

Instance Attribute Details

#end_cursorObject (readonly)

Returns the value of attribute end_cursor.



8
9
10
# File 'lib/active_shopify_graphql/response/page_info.rb', line 8

def end_cursor
  @end_cursor
end

#start_cursorObject (readonly)

Returns the value of attribute start_cursor.



8
9
10
# File 'lib/active_shopify_graphql/response/page_info.rb', line 8

def start_cursor
  @start_cursor
end

Instance Method Details

#empty?Boolean

Check if this is an empty/null page info

Returns:



26
27
28
# File 'lib/active_shopify_graphql/response/page_info.rb', line 26

def empty?
  @start_cursor.nil? && @end_cursor.nil?
end

#has_next_page?Boolean

Returns:



17
18
19
# File 'lib/active_shopify_graphql/response/page_info.rb', line 17

def has_next_page?
  @has_next_page
end

#has_previous_page?Boolean

Returns:



21
22
23
# File 'lib/active_shopify_graphql/response/page_info.rb', line 21

def has_previous_page?
  @has_previous_page
end

#to_hObject



30
31
32
33
34
35
36
37
# File 'lib/active_shopify_graphql/response/page_info.rb', line 30

def to_h
  {
    has_next_page: @has_next_page,
    has_previous_page: @has_previous_page,
    start_cursor: @start_cursor,
    end_cursor: @end_cursor
  }
end