Class: Search::GlobalService
- Inherits:
-
Object
- Object
- Search::GlobalService
- Includes:
- Gitlab::Utils::StrongMemoize, Filter
- Defined in:
- app/services/search/global_service.rb
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_SCOPE =
'projects'
- ALLOWED_SCOPES =
%w[projects issues merge_requests milestones users].freeze
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
rubocop: disable CodeReuse/ActiveRecord.
- #scope ⇒ Object
Constructor Details
#initialize(user, params) ⇒ GlobalService
Returns a new instance of GlobalService.
13 14 15 16 |
# File 'app/services/search/global_service.rb', line 13 def initialize(user, params) @current_user = user @params = params.dup end |
Instance Attribute Details
#current_user ⇒ Object
Returns the value of attribute current_user.
11 12 13 |
# File 'app/services/search/global_service.rb', line 11 def current_user @current_user end |
#params ⇒ Object
Returns the value of attribute params.
11 12 13 |
# File 'app/services/search/global_service.rb', line 11 def params @params end |
Instance Method Details
#allowed_scopes ⇒ Object
32 33 34 |
# File 'app/services/search/global_service.rb', line 32 def allowed_scopes ALLOWED_SCOPES end |
#execute ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'app/services/search/global_service.rb', line 18 def execute Gitlab::SearchResults.new(current_user, params[:search], projects, order_by: params[:order_by], sort: params[:sort], filters: filters) end |
#projects ⇒ Object
rubocop: disable CodeReuse/ActiveRecord
28 29 30 |
# File 'app/services/search/global_service.rb', line 28 def projects @projects ||= ProjectsFinder.new(current_user: current_user).execute.preload(:topics, :project_topics) end |
#scope ⇒ Object
36 37 38 39 40 |
# File 'app/services/search/global_service.rb', line 36 def scope strong_memoize(:scope) do allowed_scopes.include?(params[:scope]) ? params[:scope] : DEFAULT_SCOPE end end |