class Backframe::Response::Collection
Public Class Methods
new(collection, page, per_page)
click to toggle source
# File lib/backframe/response/collection.rb, line 9 def initialize(collection, page, per_page) @collection = collection @page = page @per_page = per_page end
Public Instance Methods
current_page()
click to toggle source
# File lib/backframe/response/collection.rb, line 23 def current_page @page ? [total_pages, @page.to_i].min : 1 end
limit()
click to toggle source
# File lib/backframe/response/collection.rb, line 27 def limit @page ? @per_page : total_records end
offset()
click to toggle source
# File lib/backframe/response/collection.rb, line 31 def offset @page ? limit * (@page - 1) : 0 end
records()
click to toggle source
# File lib/backframe/response/collection.rb, line 35 def records @page ? @collection.limit(limit).offset(offset) : @collection.all end
total_pages()
click to toggle source
# File lib/backframe/response/collection.rb, line 19 def total_pages @page ? (total_records / @per_page.to_f).ceil : 1 end
total_records()
click to toggle source
# File lib/backframe/response/collection.rb, line 15 def total_records @collection.count end