Class: Search::GlobalService

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/services/search/global_service.rb

Direct Known Subclasses

GroupService, SnippetService

Instance Attribute Summary collapse

Instance Method Summary collapse

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_userObject

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

#paramsObject

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_scopesObject


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

#executeObject


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

#projectsObject


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

#scopeObject


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