Class: ShopifyApiBruv::Resources::Rest::Pagination
- Inherits:
-
Object
- Object
- ShopifyApiBruv::Resources::Rest::Pagination
- Defined in:
- lib/shopify_api_bruv/resources/rest/pagination.rb
Instance Attribute Summary collapse
-
#page_info ⇒ Object
readonly
Returns the value of attribute page_info.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #fetch_next_page ⇒ Object
- #fetch_previous_page ⇒ Object
-
#initialize(resource:, page_info:) ⇒ Pagination
constructor
A new instance of Pagination.
- #next_page? ⇒ Boolean
- #page_exists? ⇒ Boolean
- #previous_page? ⇒ Boolean
Constructor Details
#initialize(resource:, page_info:) ⇒ Pagination
Returns a new instance of Pagination.
9 10 11 12 |
# File 'lib/shopify_api_bruv/resources/rest/pagination.rb', line 9 def initialize(resource:, page_info:) @resource = resource @page_info = page_info end |
Instance Attribute Details
#page_info ⇒ Object (readonly)
Returns the value of attribute page_info.
7 8 9 |
# File 'lib/shopify_api_bruv/resources/rest/pagination.rb', line 7 def page_info @page_info end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
7 8 9 |
# File 'lib/shopify_api_bruv/resources/rest/pagination.rb', line 7 def resource @resource end |
Instance Method Details
#fetch_next_page ⇒ Object
26 27 28 29 30 31 |
# File 'lib/shopify_api_bruv/resources/rest/pagination.rb', line 26 def fetch_next_page raise Errors::ResourceError, 'Next page cursor not found' unless next_page? resource.query[:page_info] = page_info[:next] resource.call end |
#fetch_previous_page ⇒ Object
33 34 35 36 37 38 |
# File 'lib/shopify_api_bruv/resources/rest/pagination.rb', line 33 def fetch_previous_page raise Errors::ResourceError, 'Previous page cursor not found' unless previous_page? resource.query[:page_info] = page_info[:previous] resource.call end |
#next_page? ⇒ Boolean
14 15 16 |
# File 'lib/shopify_api_bruv/resources/rest/pagination.rb', line 14 def next_page? !page_info[:next].nil? end |
#page_exists? ⇒ Boolean
22 23 24 |
# File 'lib/shopify_api_bruv/resources/rest/pagination.rb', line 22 def page_exists? next_page? || previous_page? end |
#previous_page? ⇒ Boolean
18 19 20 |
# File 'lib/shopify_api_bruv/resources/rest/pagination.rb', line 18 def previous_page? !page_info[:previous].nil? end |