Class: Serializer::Pagination

Inherits:
Upframework::BaseService
  • Object
show all
Defined in:
app/lib/serializer/pagination.rb

Constant Summary collapse

DEFAULT_PAGE =
1
DEFAULT_PER_PAGE =
20

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(records: [], page:, per_page:, **params) ⇒ Pagination

Returns a new instance of Pagination.



7
8
9
10
11
# File 'app/lib/serializer/pagination.rb', line 7

def initialize(records: [], page:, per_page:, **params)
  @records = records
  @page = page
  @per_page = per_page
end

Instance Attribute Details

#pageObject

Returns the value of attribute page.



5
6
7
# File 'app/lib/serializer/pagination.rb', line 5

def page
  @page
end

#per_pageObject

Returns the value of attribute per_page.



5
6
7
# File 'app/lib/serializer/pagination.rb', line 5

def per_page
  @per_page
end

#recordsObject

Returns the value of attribute records.



5
6
7
# File 'app/lib/serializer/pagination.rb', line 5

def records
  @records
end

Instance Method Details

#executeObject



13
14
15
# File 'app/lib/serializer/pagination.rb', line 13

def execute
  paginate_scope
end

#paginate_scopeObject



21
22
23
24
25
# File 'app/lib/serializer/pagination.rb', line 21

def paginate_scope
  @records = records.
    page(page || DEFAULT_PAGE).
    per(per_page || DEFAULT_PER_PAGE)
end

#resultObject



17
18
19
# File 'app/lib/serializer/pagination.rb', line 17

def result
  records
end