def safe_value? exp
return true unless sexp? exp
case exp.node_type
when :str, :lit, :const, :colon2, :nil, :true, :false
true
when :call
if exp.method == :to_s or exp.method == :to_sym
safe_value? exp.target
else
IGNORE_METHODS_IN_SQL.include? exp.method or
quote_call? exp or
arel? exp or
exp.method.to_s.end_with? "_id"
end
when :if
safe_value? exp.then_clause and safe_value? exp.else_clause
when :block, :rlist
safe_value? exp.last
when :or
safe_value? exp.lhs and safe_value? exp.rhs
when :dstr
not unsafe_string_interp? exp
else
false
end
end