lib/torque/postgresql/arel/visitors.rb in torque-postgresql-0.2.16 vs lib/torque/postgresql/arel/visitors.rb in torque-postgresql-1.0.0

- old
+ new

@@ -1,10 +1,9 @@ module Torque module PostgreSQL module Arel module Visitors - # Enclose select manager with parenthesis # :TODO: Remove when checking the new version of Arel def visit_Arel_SelectManager o, collector collector << '(' visit(o.ast, collector) << ')' @@ -14,11 +13,38 @@ def visit_Arel_Nodes_JoinSource(o, collector) collector << 'ONLY ' if o.only? super end + # Allow quoted arrays to get here + def visit_Arel_Nodes_Quoted(o, collector) + return super unless o.expr.is_a?(::Enumerable) + quote_array(o.expr, collector) + end + + # Allow quoted arrays to get here + def visit_Arel_Nodes_Casted(o, collector) + return super unless o.val.is_a?(::Enumerable) + quote_array(o.val, collector) + end + + ## TORQUE VISITORS + # Allow casting any node + def visit_Torque_PostgreSQL_Arel_Nodes_Cast(o, collector) + visit(o.left, collector) << '::' << o.right + end + + private + + def quote_array(value, collector) + value = value.map(&::Arel::Nodes.method(:build_quoted)) + + collector << 'ARRAY[' + visit_Array(value, collector) + collector << ']' + end end - ::Arel::Visitors::PostgreSQL.include Visitors + ::Arel::Visitors::PostgreSQL.prepend(Visitors) end end end