Class: Search::GlobalService
- Inherits:
-
Object
- Object
- Search::GlobalService
- Includes:
- Gitlab::Utils::StrongMemoize
- Defined in:
- app/services/search/global_service.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#current_user ⇒ Object
Returns the value of attribute current_user.
-
#params ⇒ Object
Returns the value of attribute params.
Instance Method Summary collapse
- #allowed_scopes ⇒ Object
- #execute ⇒ Object
-
#initialize(user, params) ⇒ GlobalService
constructor
A new instance of GlobalService.
- #projects ⇒ Object
- #scope ⇒ Object
Methods included from Gitlab::Utils::StrongMemoize
#clear_memoization, #strong_memoize, #strong_memoized?
Constructor Details
#initialize(user, params) ⇒ GlobalService
Returns a new instance of GlobalService.
9 10 11 |
# File 'app/services/search/global_service.rb', line 9 def initialize(user, params) @current_user, @params = user, params.dup end |
Instance Attribute Details
#current_user ⇒ Object
Returns the value of attribute current_user
7 8 9 |
# File 'app/services/search/global_service.rb', line 7 def current_user @current_user end |
#params ⇒ Object
Returns the value of attribute params
7 8 9 |
# File 'app/services/search/global_service.rb', line 7 def params @params end |
Instance Method Details
#allowed_scopes ⇒ Object
24 25 26 27 28 29 |
# File 'app/services/search/global_service.rb', line 24 def allowed_scopes strong_memoize(:allowed_scopes) do allowed_scopes = %w[issues merge_requests milestones] allowed_scopes << 'users' if Feature.enabled?(:users_search, default_enabled: true) end end |
#execute ⇒ Object
13 14 15 16 17 18 |
# File 'app/services/search/global_service.rb', line 13 def execute Gitlab::SearchResults.new(current_user, params[:search], projects, filters: { state: params[:state] }) end |
#projects ⇒ Object
20 21 22 |
# File 'app/services/search/global_service.rb', line 20 def projects @projects ||= ProjectsFinder.new(params: { non_archived: true }, current_user: current_user).execute end |
#scope ⇒ Object
31 32 33 34 35 |
# File 'app/services/search/global_service.rb', line 31 def scope strong_memoize(:scope) do allowed_scopes.include?(params[:scope]) ? params[:scope] : 'projects' end end |