Class: AutoSelect2::Select2SearchAdapter::Default

Inherits:
Base
  • Object
show all
Defined in:
lib/auto_select2/select2_search_adapter/default.rb

Class Method Summary collapse

Methods inherited from Base

limit, search_from_autocomplete

Class Method Details

.search_default(term, page, options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/auto_select2/select2_search_adapter/default.rb', line 5

def search_default(term, page, options)
  if !@searchable_class || @id_column.blank? || @text_columns.blank?
    raise_not_implemented
  end
  if options[:init].nil?
    default_values =
        default_finder(@searchable_class,
                       term,
                       page: page,
                       column: @text_columns,
                       case_sensitive: @case_sensitive.nil? ? options[:case_sensitive] : @case_sensitive)
    total_count =
        default_count(@searchable_class,
                      term,
                      column: @text_columns,
                      case_sensitive: @case_sensitive.nil? ? options[:case_sensitive] : @case_sensitive)
    {
        items: default_values.map do |default_value|
          get_select2_hash(
              default_value,
              @select2_hash_method,
              @id_column,
              @text_columns
          )
        end,
        total: total_count
    }
  else
    options[:id_column] = @id_column
    options[:text_columns] = @text_columns
    get_init_values(
        @searchable_class,
        options[:item_ids],
        options
    )
  end
end