tomdoc'd
This commit is contained in:
@@ -3,16 +3,31 @@ module Gollum
|
|||||||
def self.included(klass)
|
def self.included(klass)
|
||||||
klass.extend ClassMethods
|
klass.extend ClassMethods
|
||||||
class << klass
|
class << klass
|
||||||
|
# Default Integer max count of items to return in git commands.
|
||||||
attr_accessor :per_page
|
attr_accessor :per_page
|
||||||
end
|
end
|
||||||
klass.per_page = 30
|
klass.per_page = 30
|
||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
|
# Turns a page number into an offset number for the git skip option.
|
||||||
|
#
|
||||||
|
# page - Integer page number.
|
||||||
|
#
|
||||||
|
# Returns an Integer.
|
||||||
def page_to_skip(page)
|
def page_to_skip(page)
|
||||||
([1, page.to_i].max - 1) * per_page
|
([1, page.to_i].max - 1) * per_page
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# 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.
|
||||||
def log_pagination_options(options = {})
|
def log_pagination_options(options = {})
|
||||||
skip = page_to_skip(options.delete(:page))
|
skip = page_to_skip(options.delete(:page))
|
||||||
options[:max_count] = [options.delete(:per_page).to_i, per_page].max
|
options[:max_count] = [options.delete(:per_page).to_i, per_page].max
|
||||||
@@ -21,10 +36,24 @@ module Gollum
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Turns a page number into an offset number for the git skip option.
|
||||||
|
#
|
||||||
|
# page - Integer page number.
|
||||||
|
#
|
||||||
|
# Returns an Integer.
|
||||||
def page_to_skip(page)
|
def page_to_skip(page)
|
||||||
self.class.page_to_skip(page)
|
self.class.page_to_skip(page)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# 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.
|
||||||
def log_pagination_options(options = {})
|
def log_pagination_options(options = {})
|
||||||
self.class.log_pagination_options(options)
|
self.class.log_pagination_options(options)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user