Class: PuppetHerald::Models::Pagination

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet-herald/models.rb

Overview

Pagianation object

Constant Summary collapse

KEYS =

Pagination headers

{
  page: 'X-Paginate-Page',
  limit: 'X-Paginate-Limit',
  total: 'X-Paginate-Elements',
  pages: 'X-Paginate-Pages'
}
DEFAULT =

A default pagination settings

PuppetHerald::Models::Pagination.new(1, 20)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page, limit) ⇒ Pagination

A constructor

Parameters:

  • page (Integer)

    page to fetch

  • limit (Integer)

    pagination limit



34
35
36
37
38
39
40
41
42
# File 'lib/puppet-herald/models.rb', line 34

def initialize(page, limit)
  msg = 'Invalid value for pagination'
  fail ArgumentError, "#{msg} limit - #{limit.inspect}" unless limit.to_i >= 1
  fail ArgumentError, "#{msg} page #{page.inspect}" if page.to_i < 1
  @limit = limit.to_i
  @page = page.to_i
  @total = nil
  @pages = nil
end

Instance Attribute Details

#limitInteger (readonly)

Pagination attribute limit

Returns:

  • (Integer)

    pagination



16
17
18
# File 'lib/puppet-herald/models.rb', line 16

def limit
  @limit
end

#pageInteger (readonly)

Pagination attribute limit

Returns:

  • (Integer)

    pagination



16
17
18
# File 'lib/puppet-herald/models.rb', line 16

def page
  @page
end

#pagesInteger (readonly)

Pagination attribute limit

Returns:

  • (Integer)

    pagination



16
17
18
# File 'lib/puppet-herald/models.rb', line 16

def pages
  @pages
end

#totalInteger

Pagination attribute limit

Returns:

  • (Integer)

    pagination



16
17
18
# File 'lib/puppet-herald/models.rb', line 16

def total
  @total
end

Instance Method Details

#offsetInteger

Pagination attribute offset

Returns:

  • (Integer)

    pagination



19
20
21
# File 'lib/puppet-herald/models.rb', line 19

def offset
  (page - 1) * limit
end