Class: PR::Pin::Adapter::PaginatedResponse
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- PR::Pin::Adapter::PaginatedResponse
- Defined in:
- lib/pr/pin/adapter/paginated_response.rb
Instance Attribute Summary collapse
-
#pagination_params ⇒ Object
readonly
Returns the value of attribute pagination_params.
Instance Method Summary collapse
- #class ⇒ Object
- #current_page ⇒ Object
-
#initialize(dataset, pagination_params = {}) ⇒ PaginatedResponse
constructor
A new instance of PaginatedResponse.
- #next_page ⇒ Object
- #paginates? ⇒ Boolean
- #per_page ⇒ Object
- #prev_page ⇒ Object
- #total_count ⇒ Object
- #total_pages ⇒ Object
Constructor Details
#initialize(dataset, pagination_params = {}) ⇒ PaginatedResponse
Returns a new instance of PaginatedResponse.
7 8 9 10 |
# File 'lib/pr/pin/adapter/paginated_response.rb', line 7 def initialize(dataset, pagination_params = {}) super(dataset) @pagination_params = pagination_params end |
Instance Attribute Details
#pagination_params ⇒ Object (readonly)
Returns the value of attribute pagination_params.
5 6 7 |
# File 'lib/pr/pin/adapter/paginated_response.rb', line 5 def pagination_params @pagination_params end |
Instance Method Details
#class ⇒ Object
40 41 42 |
# File 'lib/pr/pin/adapter/paginated_response.rb', line 40 def class __getobj__.class end |
#current_page ⇒ Object
16 17 18 |
# File 'lib/pr/pin/adapter/paginated_response.rb', line 16 def current_page pagination_params[:current] end |
#next_page ⇒ Object
24 25 26 |
# File 'lib/pr/pin/adapter/paginated_response.rb', line 24 def next_page current_page.next if current_page && current_page < total_pages end |
#paginates? ⇒ Boolean
12 13 14 |
# File 'lib/pr/pin/adapter/paginated_response.rb', line 12 def paginates? true end |
#per_page ⇒ Object
20 21 22 |
# File 'lib/pr/pin/adapter/paginated_response.rb', line 20 def per_page pagination_params[:per_page] end |
#prev_page ⇒ Object
28 29 30 |
# File 'lib/pr/pin/adapter/paginated_response.rb', line 28 def prev_page current_page.pred if current_page && current_page > 1 end |
#total_count ⇒ Object
36 37 38 |
# File 'lib/pr/pin/adapter/paginated_response.rb', line 36 def total_count pagination_params[:count] end |
#total_pages ⇒ Object
32 33 34 |
# File 'lib/pr/pin/adapter/paginated_response.rb', line 32 def total_pages (total_count / per_page.to_f).ceil if total_count && per_page end |