Class: QuickSearch::Adapters::ActiveRecordAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/quick-search/adapters/active_record_adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(cls) ⇒ ActiveRecordAdapter

Returns a new instance of ActiveRecordAdapter.



4
5
6
# File 'lib/quick-search/adapters/active_record_adapter.rb', line 4

def initialize(cls)
  @cls = cls
end

Instance Method Details

#default_quick_search_fieldsObject



15
16
17
# File 'lib/quick-search/adapters/active_record_adapter.rb', line 15

def default_quick_search_fields
  @cls.columns.select { |c| c.type == :string }.map(&:name)
end

#make_clauses_for_token(s, token, fields) ⇒ Object



8
9
10
11
12
13
# File 'lib/quick-search/adapters/active_record_adapter.rb', line 8

def make_clauses_for_token(s, token, fields)
  s = s.joins calculate_needed_joins(fields)
  s = s.where build_parameterized_condition(fields, :s),
              s: "%#{token}%"
  s
end