Class: EasyBroker::PaginatedResponse
- Inherits:
-
Object
- Object
- EasyBroker::PaginatedResponse
- Includes:
- Enumerable
- Defined in:
- lib/easy_broker/paginated_response.rb
Instance Attribute Summary collapse
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #each ⇒ Object
- #find_each ⇒ Object
-
#initialize(query) ⇒ PaginatedResponse
constructor
A new instance of PaginatedResponse.
- #limit ⇒ Object
- #next_page ⇒ Object
- #page ⇒ Object
- #total ⇒ Object
Constructor Details
#initialize(query) ⇒ PaginatedResponse
Returns a new instance of PaginatedResponse.
6 7 8 9 |
# File 'lib/easy_broker/paginated_response.rb', line 6 def initialize(query) @query = query @response = query.get end |
Instance Attribute Details
#query ⇒ Object (readonly)
Returns the value of attribute query.
4 5 6 |
# File 'lib/easy_broker/paginated_response.rb', line 4 def query @query end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
4 5 6 |
# File 'lib/easy_broker/paginated_response.rb', line 4 def response @response end |
Instance Method Details
#each ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/easy_broker/paginated_response.rb', line 39 def each return response.content.to_enum(:each) unless block_given? response.content.each do |object| yield object end end |
#find_each ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/easy_broker/paginated_response.rb', line 29 def find_each return self.to_enum(:find_each) unless block_given? loop do each do |object| yield object end break unless next_page end end |
#limit ⇒ Object
15 16 17 |
# File 'lib/easy_broker/paginated_response.rb', line 15 def limit pagination&.limit end |
#next_page ⇒ Object
23 24 25 26 27 |
# File 'lib/easy_broker/paginated_response.rb', line 23 def next_page if page * limit < total @response = query.get(page + 1) end end |
#page ⇒ Object
19 20 21 |
# File 'lib/easy_broker/paginated_response.rb', line 19 def page pagination&.page || 1 end |
#total ⇒ Object
11 12 13 |
# File 'lib/easy_broker/paginated_response.rb', line 11 def total pagination&.total end |