Class: Gitlab::SearchContext

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/search_context.rb

Overview

Holds the contextual data used by navbar search component to determine the search scope, whether to search for code, or if a search should target snippets.

Use the SearchContext::Builder to create an instance of this class

Defined Under Namespace

Modules: ControllerConcern Classes: Builder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSearchContext

Returns a new instance of SearchContext.


15
16
17
18
19
20
21
22
23
24
# File 'lib/gitlab/search_context.rb', line 15

def initialize
  @ref = nil
  @project = nil
  @project_metadata = {}
  @group = nil
  @group_metadata = {}
  @snippets = []
  @scope = nil
  @search_url = nil
end

Instance Attribute Details

#groupObject

Returns the value of attribute group


10
11
12
# File 'lib/gitlab/search_context.rb', line 10

def group
  @group
end

#group_metadataObject

Returns the value of attribute group_metadata


10
11
12
# File 'lib/gitlab/search_context.rb', line 10

def 
  @group_metadata
end

#projectObject

Returns the value of attribute project


10
11
12
# File 'lib/gitlab/search_context.rb', line 10

def project
  @project
end

#project_metadataObject

Returns the value of attribute project_metadata


10
11
12
# File 'lib/gitlab/search_context.rb', line 10

def 
  @project_metadata
end

#refObject

Returns the value of attribute ref


10
11
12
# File 'lib/gitlab/search_context.rb', line 10

def ref
  @ref
end

#scopeObject

Returns the value of attribute scope


10
11
12
# File 'lib/gitlab/search_context.rb', line 10

def scope
  @scope
end

#search_urlObject

Returns the value of attribute search_url


10
11
12
# File 'lib/gitlab/search_context.rb', line 10

def search_url
  @search_url
end

#snippetsObject

Returns the value of attribute snippets


10
11
12
# File 'lib/gitlab/search_context.rb', line 10

def snippets
  @snippets
end

Instance Method Details

#code_search?Boolean

Returns:

  • (Boolean)

38
39
40
# File 'lib/gitlab/search_context.rb', line 38

def code_search?
  project.present? && scope.nil?
end

#for_group?Boolean

Returns:

  • (Boolean)

30
31
32
# File 'lib/gitlab/search_context.rb', line 30

def for_group?
  group.present? && group.persisted?
end

#for_project?Boolean

Returns:

  • (Boolean)

26
27
28
# File 'lib/gitlab/search_context.rb', line 26

def for_project?
  project.present? && project.persisted?
end

#for_snippets?Boolean

Returns:

  • (Boolean)

34
35
36
# File 'lib/gitlab/search_context.rb', line 34

def for_snippets?
  snippets.any?
end