Class: PR::Pin::Adapter::PaginatedResponse

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/pr/pin/adapter/paginated_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_paramsObject (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

#classObject



40
41
42
# File 'lib/pr/pin/adapter/paginated_response.rb', line 40

def class
  __getobj__.class
end

#current_pageObject



16
17
18
# File 'lib/pr/pin/adapter/paginated_response.rb', line 16

def current_page
  pagination_params[:current]
end

#next_pageObject



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

Returns:

  • (Boolean)


12
13
14
# File 'lib/pr/pin/adapter/paginated_response.rb', line 12

def paginates?
  true
end

#per_pageObject



20
21
22
# File 'lib/pr/pin/adapter/paginated_response.rb', line 20

def per_page
  pagination_params[:per_page]
end

#prev_pageObject



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_countObject



36
37
38
# File 'lib/pr/pin/adapter/paginated_response.rb', line 36

def total_count
  pagination_params[:count]
end

#total_pagesObject



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