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.



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

def filterable_fields
  @filterable_fields
end

Instance Method Details

#filter(query) ⇒ Object



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

def 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

#filterable_by(*fields) ⇒ Object



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

def filterable_by(*fields)
  @filterable_fields = fields
end