class PuppetHerald::Models::Pagination
Pagianation object
Constants
- DEFAULT
A default pagination settings
- KEYS
Pagination
headers
Attributes
limit[R]
Pagination
attribute limit @return [Integer] pagination
page[R]
Pagination
attribute limit @return [Integer] pagination
pages[R]
Pagination
attribute limit @return [Integer] pagination
total[R]
Pagination
attribute limit @return [Integer] pagination
Public Class Methods
new(page, limit)
click to toggle source
A constructor
@param page [Integer] page to fetch @param limit [Integer] pagination limit
# 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
Public Instance Methods
offset()
click to toggle source
Pagination
attribute offset @return [Integer] pagination
# File lib/puppet-herald/models.rb, line 19 def offset (page - 1) * limit end
total=(total)
click to toggle source
Sets a total elements for pagination @param total [Integer] a total number of elements @return [nil]
# File lib/puppet-herald/models.rb, line 25 def total=(total) @total = total.to_i @pages = (@total / @limit.to_f).ceil nil end