Module: Katalyst::Tables::Collection::Suggestions

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/katalyst/tables/collection/suggestions.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#suggestions(position: self.position) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/models/concerns/katalyst/tables/collection/suggestions.rb', line 16

def suggestions(position: self.position)
  query_token = token_at_position(position:)

  attribute = attribute_for_token(query_token:)
  method    = suggestions_method(attribute) if attribute.present?

  # build a suggestions list
  suggestions = if method && respond_to?(method)
                  user_suggestions(attribute:, method:)
                elsif attribute
                  value_suggestions(attribute:)
                else
                  attribute_suggestions(query_token:)
                end

  add_context_suggestions(suggestions:, query_token:, attribute:) if query_token

  suggestions
end