Class: Gitlab::ProjectSearchResults

Inherits:
SearchResults show all
Defined in:
lib/gitlab/project_search_results.rb

Instance Attribute Summary collapse

Attributes inherited from SearchResults

#current_user, #limit_projects, #query

Instance Method Summary collapse

Methods inherited from SearchResults

#empty?, #issues_count, #merge_requests_count, #milestones_count, #projects_count

Constructor Details

#initialize(current_user, project, query, repository_ref = nil) ⇒ ProjectSearchResults

Returns a new instance of ProjectSearchResults


5
6
7
8
9
10
11
12
13
14
# File 'lib/gitlab/project_search_results.rb', line 5

def initialize(current_user, project, query, repository_ref = nil)
  @current_user = current_user
  @project = project
  @repository_ref = if repository_ref.present?
                      repository_ref
                    else
                      nil
                    end
  @query = query
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project


3
4
5
# File 'lib/gitlab/project_search_results.rb', line 3

def project
  @project
end

#repository_refObject (readonly)

Returns the value of attribute repository_ref


3
4
5
# File 'lib/gitlab/project_search_results.rb', line 3

def repository_ref
  @repository_ref
end

Instance Method Details

#blobs_countObject


36
37
38
# File 'lib/gitlab/project_search_results.rb', line 36

def blobs_count
  @blobs_count ||= blobs.count
end

#commits_countObject


48
49
50
# File 'lib/gitlab/project_search_results.rb', line 48

def commits_count
  @commits_count ||= commits.count
end

#notes_countObject


40
41
42
# File 'lib/gitlab/project_search_results.rb', line 40

def notes_count
  @notes_count ||= notes.count
end

#objects(scope, page = nil) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gitlab/project_search_results.rb', line 16

def objects(scope, page = nil)
  case scope
  when 'notes'
    notes.page(page).per(per_page)
  when 'blobs'
    Kaminari.paginate_array(blobs).page(page).per(per_page)
  when 'wiki_blobs'
    Kaminari.paginate_array(wiki_blobs).page(page).per(per_page)
  when 'commits'
    Kaminari.paginate_array(commits).page(page).per(per_page)
  else
    super
  end
end

#total_countObject


31
32
33
34
# File 'lib/gitlab/project_search_results.rb', line 31

def total_count
  @total_count ||= issues_count + merge_requests_count + blobs_count +
                   notes_count + wiki_blobs_count + commits_count
end

#wiki_blobs_countObject


44
45
46
# File 'lib/gitlab/project_search_results.rb', line 44

def wiki_blobs_count
  @wiki_blobs_count ||= wiki_blobs.count
end