Module: Gollum::Pagination::ClassMethods

Defined in:
lib/gollum/pagination.rb

Instance Method Summary collapse

Instance Method Details

#log_pagination_options(options = {}) ⇒ Object

Fills in git-specific options for the log command using simple pagination options.

options - Hash of options:

page - Optional Integer page number (default: 1)
per_page - Optional Integer max count of items to return.
           Defaults to #per_class class method.

Returns Hash with :max_count and :skip keys.



31
32
33
34
35
36
# File 'lib/gollum/pagination.rb', line 31

def log_pagination_options(options = {})
  skip = page_to_skip(options.delete(:page))
  options[:max_count] = [options.delete(:per_page).to_i, per_page].max
  options[:skip]      = skip if skip > 0
  options
end

#page_to_skip(page) ⇒ Object

Turns a page number into an offset number for the git skip option.

page - Integer page number.

Returns an Integer.



18
19
20
# File 'lib/gollum/pagination.rb', line 18

def page_to_skip(page)
  ([1, page.to_i].max - 1) * per_page
end