Class: TheGrid::Api::Command::Search

Inherits:
TheGrid::Api::Command show all
Defined in:
lib/the_grid/api/command/search.rb

Instance Method Summary collapse

Methods inherited from TheGrid::Api::Command

#batch?, build, #contextualize, #execute_on, find, register_lookup_scope, scopes

Instance Method Details

#configure(relation, params) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/the_grid/api/command/search.rb', line 3

def configure(relation, params)
  {}.tap do |o|
    o[:query] = params.fetch(:query, '').strip
    o[:searchable_columns] = params[:searchable_columns]
    o[:search_over] = params[:search_over]
    o[:search_over] = Hash[o[:search_over].zip] if o[:search_over].kind_of?(Array)
  end
end

#run_on(relation, params) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/the_grid/api/command/search.rb', line 12

def run_on(relation, params)
  if params[:query].blank?
    relation
  elsif params[:search_over].present?
    search_over(relation, params)
  else
    relation.where build_conditions_for(relation, params)
  end
end