Class: Debci::App

Inherits:
Sinatra::Base
  • Object
show all
Includes:
ERB::Util
Defined in:
lib/debci/app.rb

Direct Known Subclasses

Frontend, SelfService, Status, SelfDocAPI

Defined Under Namespace

Classes: Page

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_page_range(current, total) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/debci/app.rb', line 16

def self.get_page_range(current, total)
  full_range = (1..total)
  middle = ((current - 5)..(current + 5)).select { |i| full_range.include?(i) }
  start = middle.include?(1) ? [] : [1, nil]
  finish = middle.include?(total) ? [] : [nil, total]
  start + middle + finish
end

Instance Method Details

#get_page_params(records, page, per_page_limit) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/debci/app.rb', line 30

def get_page_params(records, page, per_page_limit)
  current_page = page || 1
  records = records.page(current_page).per(per_page_limit)
  total_pages = records.total_pages
  pages = get_page_range(Integer(current_page), total_pages)
  Page.new(current_page, records, total_pages, pages)
end

#get_page_range(current, total) ⇒ Object



24
25
26
# File 'lib/debci/app.rb', line 24

def get_page_range(current, total)
  self.class.get_page_range(current, total)
end

#pagination_params(page) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/debci/app.rb', line 38

def pagination_params(page)
  query = {}
  request.env['rack.request.query_hash'].each do |key, value|
    key = "#{key}[]".to_sym if value.is_a?(Array)
    query[key] = value
  end
  query.merge!(page: page)
  URI.encode_www_form(query)
end