Module: Lipstick::Filterable::ClassMethods

Defined in:
lib/lipstick/filterable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#filterable_fieldsObject (readonly)

Returns the value of attribute filterable_fields.



31
32
33
# File 'lib/lipstick/filterable.rb', line 31

def filterable_fields
  @filterable_fields
end

Instance Method Details

#filterable_by(*fields) ⇒ Object



33
34
35
# File 'lib/lipstick/filterable.rb', line 33

def filterable_by(*fields)
  @filterable_fields = fields
end

#filterable_filter(query) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/lipstick/filterable.rb', line 37

def filterable_filter(query)
  filter_terms(query).reduce(all) do |scope, term|
    conds = filterable_fields.map do |f|
      CollatedArelAttribute.new(arel_table[f], 'utf8_unicode_ci')
                           .matches(term)
    end
    scope.where(conds.reduce { |acc, elem| acc.or(elem) })
  end
end