10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/friendly/sequel_monkey_patches.rb', line 10
def self.from_value_pairs(pairs, op=:AND, negate=false)
pairs = pairs.collect do |l,r|
ce = case r
when Range
new(:AND, new(:>=, l, r.begin), new(r.exclude_end? ? :< : :<=, l, r.end))
when Array, ::Sequel::Dataset, SQLArray
new(:IN, l, r)
when NegativeBooleanConstant
new(:"IS NOT", l, r.constant)
when BooleanConstant
new(:IS, l, r.constant)
when NilClass
new(:IS, l, r)
when Regexp
StringExpression.like(l, r)
else
new(:'=', l, r)
end
negate ? invert(ce) : ce
end
pairs.length == 1 ? pairs.at(0) : new(op, *pairs)
end
|