Class: User::Autocomplete

Inherits:
Queries::Query show all
Defined in:
lib/queries/user/autocomplete.rb

Instance Attribute Summary

Attributes inherited from Queries::Query

#dynamic_limit, #options, #project_id, #query_string, #terms

Instance Method Summary (collapse)

Methods inherited from Queries::Query

#alphabetic_strings, #autocomplete_cached, #autocomplete_cached_wildcard_anywhere, #autocomplete_exact_id, #autocomplete_ordered_wildcard_pieces_in_cached, #autocomplete_start_date, #build_terms, #cached, #combine_or_clauses, #end_wildcard, #exactly_named, #fragments, #initialize, #integers, #match_ordered_wildcard_pieces_in_cached, #match_wildcard_end_in_cached, #match_wildcard_in_cached, #named, #no_digits, #only_ids, #only_integers?, #parent, #parent_child_join, #parent_child_where, #pieces, #result, #scope, #simple_date, #start_and_end_wildcard, #start_wildcard, #wildcard_pieces, #wildcard_wrapped_integers, #wildcard_wrapped_years, #with_cached, #with_cached_like, #with_id, #with_project_id, #with_start_date, #year_letter, #years

Constructor Details

This class inherits a constructor from Queries::Query

Instance Method Details

- (Scope) autocomplete

Returns:

  • (Scope)


30
31
32
33
# File 'lib/queries/user/autocomplete.rb', line 30

def autocomplete 
  # For reference, this is equivalent: Otu.eager_load(:taxon_name).where(where_sql)
  ::User.where(where_sql).order(name: :asc)
end

- (Scope) or_clauses

Returns:

  • (Scope)


10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/queries/user/autocomplete.rb', line 10

def or_clauses
  clauses = [
    named,
    with_email,
    with_id
  ].compact

  a = clauses.shift
  clauses.each do |b|
    a = a.or(b)
  end
  a
end

- (Arel::Table) table

Returns:

  • (Arel::Table)


36
37
38
# File 'lib/queries/user/autocomplete.rb', line 36

def table
  ::User.arel_table
end

- (Scope) where_sql

Returns:

  • (Scope)


5
6
7
# File 'lib/queries/user/autocomplete.rb', line 5

def where_sql
  or_clauses.to_sql
end

- (Arel::Nodes::Matches) with_email

Returns:

  • (Arel::Nodes::Matches)


25
26
27
# File 'lib/queries/user/autocomplete.rb', line 25

def with_email
  table[:email].matches_any(terms) if terms.any?
end