Class: Autocomplete::RoutesFinder

Inherits:
Object
  • Object
show all
Defined in:
app/finders/autocomplete/routes_finder.rb

Overview

Finder that returns a list of routes that match on the `path` attribute.

Direct Known Subclasses

NamespacesOnly, ProjectsOnly

Defined Under Namespace

Classes: NamespacesOnly, ProjectsOnly

Constant Summary collapse

LIMIT =
20

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_user, params = {}) ⇒ RoutesFinder

Returns a new instance of RoutesFinder.


10
11
12
13
# File 'app/finders/autocomplete/routes_finder.rb', line 10

def initialize(current_user, params = {})
  @current_user = current_user
  @search = params[:search]
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user


6
7
8
# File 'app/finders/autocomplete/routes_finder.rb', line 6

def current_user
  @current_user
end

#searchObject (readonly)

Returns the value of attribute search


6
7
8
# File 'app/finders/autocomplete/routes_finder.rb', line 6

def search
  @search
end

Instance Method Details

#executeObject


15
16
17
18
19
20
21
22
23
# File 'app/finders/autocomplete/routes_finder.rb', line 15

def execute
  return [] if @search.blank?

  Route
    .for_routable(routables)
    .sort_by_path_length
    .fuzzy_search(@search, [:path])
    .limit(LIMIT) # rubocop: disable CodeReuse/ActiveRecord
end