class Gollum::Sorters::WikiSorter
Constants
- SORT_CREATED_AT
Attributes
direction_desc[R]
limit[R]
sort[R]
Public Class Methods
new(sort, direction_desc, limit)
click to toggle source
# File lib/gollum-lib/sorters/wiki_sorter.rb, line 8 def initialize(sort, direction_desc, limit) @sort = sort @direction_desc = direction_desc @limit = limit end
Public Instance Methods
call(sha, access, blobs)
click to toggle source
# File lib/gollum-lib/sorters/wiki_sorter.rb, line 14 def call(sha, access, blobs) if sort == SORT_CREATED_AT by_created_at(sha, access, blobs) else by_title(blobs) end end
Private Instance Methods
by_created_at(sha, access, blobs)
click to toggle source
# File lib/gollum-lib/sorters/wiki_sorter.rb, line 24 def by_created_at(sha, access, blobs) blobs_by_path = blobs.each_with_object({}) do |entry, hash| hash[entry.path] = entry end filenames = access.files_sorted_by_created_at(sha) iterator = direction_desc ? filenames.each : filenames.reverse_each iterator.with_object([]) do |filename, blobs| blob = blobs_by_path[filename] next unless blob blobs << blob break blobs if limit && blobs.size == limit end end
by_title(blobs)
click to toggle source
# File lib/gollum-lib/sorters/wiki_sorter.rb, line 40 def by_title(blobs) blobs = blobs.reverse if direction_desc blobs = blobs.take(limit) if limit blobs end