16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/acts_as_queryable.rb', line 16
def query(query_params)
conditions = []
params = []
query_params.each do |key, value|
key = key.to_s
next unless self.columns_hash[key] && @query_param_names.include?(key)
if value == 'NULL'
conditions << "#{key} IS NULL"
next
end
case self.columns_hash[key].type
when :string, :text
conditions << "#{key} LIKE ?"
params << "%#{value}%"
when :integer
sub_conditions = []
value.split(',').each do |integer|
sub_conditions << "#{key} = ?"
params << integer
end
conditions << "(#{sub_conditions.join(' OR ')})"
else
conditions << "#{key} = ?"
params << value
end
end
query_params.each do |key, value|
key = key.to_s
suffix = suffix(key)
key = remove_suffix(key)
next unless self.columns_hash[key]
case self.columns_hash[key].type
when :integer, :float, :datetime
case suffix
when 'gt'
conditions << "#{key} > ?"
params << value
when 'lt'
conditions << "#{key} < ?"
params << value
end
end
end
query = conditions.join(' AND ')
self.where(query, *params).order(@order && query_params[:order])
end
|