Class: Filternator::Pagination

Inherits:
Object
  • Object
show all
Defined in:
lib/filternator/pagination.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope) ⇒ Pagination

Returns a new instance of Pagination.



6
7
8
# File 'lib/filternator/pagination.rb', line 6

def initialize(scope)
  @scope = scope
end

Instance Attribute Details

#scopeObject (readonly)

Returns the value of attribute scope.



4
5
6
# File 'lib/filternator/pagination.rb', line 4

def scope
  @scope
end

Instance Method Details

#as_jsonObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/filternator/pagination.rb', line 10

def as_json(*)
  {
    total:          scope.total_entries,
    total_pages:    scope.total_pages,
    first_page:     scope.current_page == 1,
    last_page:      scope.next_page.blank?,
    current_page:   scope.current_page,
    previous_page:  scope.previous_page,
    next_page:      scope.next_page,
    out_of_bounds:  scope.out_of_bounds?,
    offset:         scope.offset
  }
end