Class: Yaqb::QueryBuilders::Paginate

Inherits:
Object
  • Object
show all
Defined in:
lib/yaqb/query_builders/paginate.rb

Instance Method Summary collapse

Constructor Details

#initialize(scope, query_params, url) ⇒ Paginate

Returns a new instance of Paginate.



6
7
8
9
10
11
12
# File 'lib/yaqb/query_builders/paginate.rb', line 6

def initialize(scope, query_params, url)
  @query_params = query_params
  @page = validate_param!(:page, 1)
  @per = validate_param!(:per, default_per_page)
  @scope = paginate!(scope)
  @url = url
end

Instance Method Details



18
19
20
21
22
23
# File 'lib/yaqb/query_builders/paginate.rb', line 18

def links
  @links ||= pages.each_with_object({}) do |(k, v), hash|
    query_params = @query_params.merge('page' => v, 'per' => @per).to_param
    hash[k] = "#{@url}?#{query_params}"
  end
end

#paginateObject



14
15
16
# File 'lib/yaqb/query_builders/paginate.rb', line 14

def paginate
  @scope
end