Class: PuppetHerald::Models::Pagination
- Inherits:
-
Object
- Object
- PuppetHerald::Models::Pagination
- 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
-
#limit ⇒ Integer
readonly
Pagination attribute limit.
-
#page ⇒ Integer
readonly
Pagination attribute limit.
-
#pages ⇒ Integer
readonly
Pagination attribute limit.
-
#total ⇒ Integer
Pagination attribute limit.
Instance Method Summary collapse
-
#initialize(page, limit) ⇒ Pagination
constructor
A constructor.
-
#offset ⇒ Integer
Pagination attribute offset.
Constructor Details
#initialize(page, limit) ⇒ Pagination
A constructor
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
#limit ⇒ Integer (readonly)
Pagination attribute limit
16 17 18 |
# File 'lib/puppet-herald/models.rb', line 16 def limit @limit end |
#page ⇒ Integer (readonly)
Pagination attribute limit
16 17 18 |
# File 'lib/puppet-herald/models.rb', line 16 def page @page end |
#pages ⇒ Integer (readonly)
Pagination attribute limit
16 17 18 |
# File 'lib/puppet-herald/models.rb', line 16 def pages @pages end |
#total ⇒ Integer
Pagination attribute limit
16 17 18 |
# File 'lib/puppet-herald/models.rb', line 16 def total @total end |
Instance Method Details
#offset ⇒ Integer
Pagination attribute offset
19 20 21 |
# File 'lib/puppet-herald/models.rb', line 19 def offset (page - 1) * limit end |