Class: Gitlab::ProjectSearchResults
- Inherits:
-
SearchResults
- Object
- SearchResults
- Gitlab::ProjectSearchResults
- Defined in:
- lib/gitlab/project_search_results.rb
Constant Summary
Constants inherited from SearchResults
SearchResults::COUNT_LIMIT, SearchResults::COUNT_LIMIT_MESSAGE, SearchResults::DEFAULT_PAGE, SearchResults::DEFAULT_PER_PAGE
Instance Attribute Summary collapse
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#repository_ref ⇒ Object
readonly
Returns the value of attribute repository_ref.
Attributes inherited from SearchResults
#current_user, #default_project_filter, #filters, #limit_projects, #query
Instance Method Summary collapse
- #commits_count ⇒ Object
- #formatted_count(scope) ⇒ Object
-
#initialize(current_user, query, project:, repository_ref: nil, filters: {}) ⇒ ProjectSearchResults
constructor
A new instance of ProjectSearchResults.
- #limited_blobs_count ⇒ Object
-
#limited_notes_count ⇒ Object
rubocop: disable CodeReuse/ActiveRecord.
- #objects(scope, page: nil, per_page: DEFAULT_PER_PAGE, preload_method: nil) ⇒ Object
- #single_commit_result? ⇒ Boolean
- #users ⇒ Object
-
#wiki_blobs_count ⇒ Object
rubocop: enable CodeReuse/ActiveRecord.
Methods inherited from SearchResults
#count_limit, #formatted_limited_count, #limited_issues_count, #limited_merge_requests_count, #limited_milestones_count, #limited_projects_count, #limited_users_count
Constructor Details
#initialize(current_user, query, project:, repository_ref: nil, filters: {}) ⇒ ProjectSearchResults
Returns a new instance of ProjectSearchResults.
7 8 9 10 11 12 |
# File 'lib/gitlab/project_search_results.rb', line 7 def initialize(current_user, query, project:, repository_ref: nil, filters: {}) @project = project @repository_ref = repository_ref.presence super(current_user, query, [project], filters: filters) end |
Instance Attribute Details
#project ⇒ Object (readonly)
Returns the value of attribute project
5 6 7 |
# File 'lib/gitlab/project_search_results.rb', line 5 def project @project end |
#repository_ref ⇒ Object (readonly)
Returns the value of attribute repository_ref
5 6 7 |
# File 'lib/gitlab/project_search_results.rb', line 5 def repository_ref @repository_ref end |
Instance Method Details
#commits_count ⇒ Object
74 75 76 |
# File 'lib/gitlab/project_search_results.rb', line 74 def commits_count @commits_count ||= commits(limit: count_limit).count end |
#formatted_count(scope) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/gitlab/project_search_results.rb', line 31 def formatted_count(scope) case scope when 'blobs' formatted_limited_count(limited_blobs_count) when 'notes' formatted_limited_count(limited_notes_count) when 'wiki_blobs' wiki_blobs_count.to_s when 'commits' formatted_limited_count(commits_count) else super end end |
#limited_blobs_count ⇒ Object
50 51 52 |
# File 'lib/gitlab/project_search_results.rb', line 50 def limited_blobs_count @limited_blobs_count ||= blobs(limit: count_limit).count end |
#limited_notes_count ⇒ Object
rubocop: disable CodeReuse/ActiveRecord
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/gitlab/project_search_results.rb', line 55 def limited_notes_count return @limited_notes_count if defined?(@limited_notes_count) types = %w(issue merge_request commit snippet) @limited_notes_count = 0 types.each do |type| @limited_notes_count += notes_finder(type).limit(count_limit).count break if @limited_notes_count >= count_limit end @limited_notes_count end |
#objects(scope, page: nil, per_page: DEFAULT_PER_PAGE, preload_method: nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/gitlab/project_search_results.rb', line 14 def objects(scope, page: nil, per_page: DEFAULT_PER_PAGE, preload_method: nil) case scope when 'notes' notes.page(page).per(per_page) when 'blobs' paginated_blobs(blobs(limit: limit_up_to_page(page, per_page)), page, per_page) when 'wiki_blobs' paginated_wiki_blobs(wiki_blobs(limit: limit_up_to_page(page, per_page)), page, per_page) when 'commits' paginated_commits(page, per_page) when 'users' users.page(page).per(per_page) else super(scope, page: page, per_page: per_page, without_count: false) end end |
#single_commit_result? ⇒ Boolean
78 79 80 81 82 83 84 85 |
# File 'lib/gitlab/project_search_results.rb', line 78 def single_commit_result? return false if commits_count != 1 counts = %i(limited_milestones_count limited_notes_count limited_merge_requests_count limited_issues_count limited_blobs_count wiki_blobs_count) counts.all? { |count_method| public_send(count_method) == 0 } # rubocop:disable GitlabSecurity/PublicSend end |
#users ⇒ Object
46 47 48 |
# File 'lib/gitlab/project_search_results.rb', line 46 def users super.where(id: @project.team.members) # rubocop:disable CodeReuse/ActiveRecord end |
#wiki_blobs_count ⇒ Object
rubocop: enable CodeReuse/ActiveRecord
70 71 72 |
# File 'lib/gitlab/project_search_results.rb', line 70 def wiki_blobs_count @wiki_blobs_count ||= wiki_blobs(limit: count_limit).count end |