Class: Easyship::Pagination::Cursor
- Inherits:
-
Object
- Object
- Easyship::Pagination::Cursor
- Defined in:
- lib/easyship/pagination/cursor.rb
Overview
Represents a pagination object
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
Instance Method Summary collapse
- #all ⇒ Object
-
#initialize(client, path, params) ⇒ Cursor
constructor
A new instance of Cursor.
Constructor Details
#initialize(client, path, params) ⇒ Cursor
Returns a new instance of Cursor.
9 10 11 12 13 14 |
# File 'lib/easyship/pagination/cursor.rb', line 9 def initialize(client, path, params) @client = client @path = path @params = params @per_page = params[:per_page] || Easyship.configuration.per_page end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/easyship/pagination/cursor.rb', line 7 def client @client end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
7 8 9 |
# File 'lib/easyship/pagination/cursor.rb', line 7 def key @key end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
7 8 9 |
# File 'lib/easyship/pagination/cursor.rb', line 7 def params @params end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/easyship/pagination/cursor.rb', line 7 def path @path end |
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page.
7 8 9 |
# File 'lib/easyship/pagination/cursor.rb', line 7 def per_page @per_page end |
Instance Method Details
#all ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/easyship/pagination/cursor.rb', line 16 def all page = 1 loop do body = client.get(path, params.merge(page: page, per_page: per_page)) break if body.nil? || body.empty? yield body break if body.dig(:meta, :pagination, :next).nil? page += 1 end end |