13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/filterism/adapters/active_record_adapter.rb', line 13
def filter(conditions)
where_clause = ""
values = []
where_mark = '?'
conditions.each do |condition|
unless (@filterable_fields and not @filterable_fields.include?(condition[:key])) or (@unfilterable_fields and @unfilterable_fields.include?(condition[:key]))
if condition[:comparator] == 'LIKE'
values << "%#{condition[:value]}%"
elsif condition[:comparator] == 'IN'
where_mark = '(?)'
values << condition[:value].split(',')
else
values << convert_if_string_is_boolean(condition[:value])
end
where_clause << " AND" unless where_clause.empty?
where_clause << " #{condition[:key]} #{condition[:comparator]} #{where_mark}"
end
end
where(where_clause, *values)
end
|