Skip to content

Commit

Permalink
Fixing Arel 4.0.1 issues
Browse files Browse the repository at this point in the history
Closes #99
  • Loading branch information
danmcclain committed Oct 23, 2013
1 parent a442367 commit 4ac6184
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
7 changes: 4 additions & 3 deletions lib/postgres_ext/arel/visitors/to_sql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
module Arel
module Visitors
class ToSql
def visit_Array o
if last_column.respond_to?(:array) && last_column.array
quoted o
def visit_Array o, a
column = a.relation.engine.columns.find { |col| col.name == a.name.to_s } if a
if column && column.respond_to?(:array) && column.array
quoted o, a
else
o.empty? ? 'NULL' : o.map { |x| visit x }.join(', ')
end
Expand Down
24 changes: 12 additions & 12 deletions lib/postgres_ext/arel/visitors/visitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@ module Visitors
class Visitor
# We are adding our visitors to the main visitor for the time being until the right spot is found to monkey patch
private
def visit_Arel_Nodes_ContainedWithin o
"#{visit o.left} << #{visit o.right}"
def visit_Arel_Nodes_ContainedWithin o, a = nil
"#{visit o.left, a} << #{visit o.right, o.left}"
end

def visit_Arel_Nodes_ContainedWithinEquals o
"#{visit o.left} <<= #{visit o.right}"
def visit_Arel_Nodes_ContainedWithinEquals o, a = nil
"#{visit o.left, a} <<= #{visit o.right, o.left}"
end

def visit_Arel_Nodes_Contains o
def visit_Arel_Nodes_Contains o, a = nil
left_column = o.left.relation.engine.columns.find { |col| col.name == o.left.name.to_s }

if left_column && left_column.respond_to?(:array) && left_column.array
"#{visit o.left} @> #{visit o.right}"
"#{visit o.left, a} @> #{visit o.right, o.left}"
else
"#{visit o.left} >> #{visit o.right}"
"#{visit o.left, a} >> #{visit o.right, o.left}"
end
end

def visit_Arel_Nodes_ContainsEquals o
"#{visit o.left} >>= #{visit o.right}"
def visit_Arel_Nodes_ContainsEquals o, a = nil
"#{visit o.left, a} >>= #{visit o.right, o.left}"
end

def visit_Arel_Nodes_Overlap o
"#{visit o.left} && #{visit o.right}"
def visit_Arel_Nodes_Overlap o, a = nil
"#{visit o.left, a} && #{visit o.right, o.left}"
end

def visit_IPAddr value
def visit_IPAddr value, a = nil
"'#{value.to_s}/#{value.instance_variable_get(:@mask_addr).to_s(2).count('1')}'"
end
end
Expand Down

0 comments on commit 4ac6184

Please sign in to comment.