diff options
author | Ernie Miller <ernie@erniemiller.org> | 2013-03-16 19:20:11 -0400 |
---|---|---|
committer | Ernie Miller <ernie@erniemiller.org> | 2013-04-28 22:20:16 -0700 |
commit | 68a95542e1a7a79d9777223fbffd2b982fed0268 (patch) | |
tree | 7ae8829cefd20f214cfac9f8f1b141b4f9146739 /lib/arel/visitors/depth_first.rb | |
parent | 3ef63ac5366000b232ca5fe0848de9db9a3c1f9a (diff) | |
download | rails-68a95542e1a7a79d9777223fbffd2b982fed0268.tar.gz rails-68a95542e1a7a79d9777223fbffd2b982fed0268.tar.bz2 rails-68a95542e1a7a79d9777223fbffd2b982fed0268.zip |
Make visitors threadsafe by removing @last_column
The last_column feature of the ToSql visitor and its descendants is what
enabled quoting based on the column last visited -- in other words, if
you have a standard condition like an equality with a string attribute
on the left side and an integer on the right side, then when ARel visits
the node, it'll first visit the left side attribute, setting the
column of the string attribute as the last column, and resulting in the
right side of the condition getting the appropriate quoting.
The downside is that this means that visitors can't be shared between
threads, because of the state mutation. It also makes for some really
weird behavior in the event that the visitor visits a node that happens
to contain an attribute you weren't expecting to be there, since it'll
potentially quote something based on that attribute. So, it prevents
reversing an equality condition. column = value will work, but not value
= column, since the last column wouldn't be the column you're hoping
for.
This is a first pass at fixing this by changing the signature of the
visit methods to accept the currently-relevant attribute, if any.
Diffstat (limited to 'lib/arel/visitors/depth_first.rb')
-rw-r--r-- | lib/arel/visitors/depth_first.rb | 112 |
1 files changed, 56 insertions, 56 deletions
diff --git a/lib/arel/visitors/depth_first.rb b/lib/arel/visitors/depth_first.rb index 24c435ad1d..67cdecfa36 100644 --- a/lib/arel/visitors/depth_first.rb +++ b/lib/arel/visitors/depth_first.rb @@ -7,13 +7,13 @@ module Arel private - def visit o + def visit o, a = nil super @block.call o end - def unary o - visit o.expr + def unary o, a + visit o.expr, a end alias :visit_Arel_Nodes_Group :unary alias :visit_Arel_Nodes_Grouping :unary @@ -28,10 +28,10 @@ module Arel alias :visit_Arel_Nodes_Top :unary alias :visit_Arel_Nodes_UnqualifiedColumn :unary - def function o - visit o.expressions - visit o.alias - visit o.distinct + def function o, a + visit o.expressions, a + visit o.alias, a + visit o.distinct, a end alias :visit_Arel_Nodes_Avg :function alias :visit_Arel_Nodes_Exists :function @@ -39,27 +39,27 @@ module Arel alias :visit_Arel_Nodes_Min :function alias :visit_Arel_Nodes_Sum :function - def visit_Arel_Nodes_NamedFunction o - visit o.name - visit o.expressions - visit o.distinct - visit o.alias + def visit_Arel_Nodes_NamedFunction o, a + visit o.name, a + visit o.expressions, a + visit o.distinct, a + visit o.alias, a end - def visit_Arel_Nodes_Count o - visit o.expressions - visit o.alias - visit o.distinct + def visit_Arel_Nodes_Count o, a + visit o.expressions, a + visit o.alias, a + visit o.distinct, a end - def nary o - o.children.each { |child| visit child } + def nary o, a + o.children.each { |child| visit child, a } end alias :visit_Arel_Nodes_And :nary - def binary o - visit o.left - visit o.right + def binary o, a + visit o.left, a + visit o.right, a end alias :visit_Arel_Nodes_As :binary alias :visit_Arel_Nodes_Assignment :binary @@ -83,13 +83,13 @@ module Arel alias :visit_Arel_Nodes_TableAlias :binary alias :visit_Arel_Nodes_Values :binary - def visit_Arel_Nodes_StringJoin o - visit o.left + def visit_Arel_Nodes_StringJoin o, a + visit o.left, a end - def visit_Arel_Attribute o - visit o.relation - visit o.name + def visit_Arel_Attribute o, a + visit o.relation, a + visit o.name, a end alias :visit_Arel_Attributes_Integer :visit_Arel_Attribute alias :visit_Arel_Attributes_Float :visit_Arel_Attribute @@ -99,11 +99,11 @@ module Arel alias :visit_Arel_Attributes_Attribute :visit_Arel_Attribute alias :visit_Arel_Attributes_Decimal :visit_Arel_Attribute - def visit_Arel_Table o - visit o.name + def visit_Arel_Table o, a + visit o.name, a end - def terminal o + def terminal o, a end alias :visit_ActiveSupport_Multibyte_Chars :terminal alias :visit_ActiveSupport_StringInquirer :terminal @@ -127,43 +127,43 @@ module Arel alias :visit_Time :terminal alias :visit_TrueClass :terminal - def visit_Arel_Nodes_InsertStatement o - visit o.relation - visit o.columns - visit o.values + def visit_Arel_Nodes_InsertStatement o, a + visit o.relation, a + visit o.columns, a + visit o.values, a end - def visit_Arel_Nodes_SelectCore o - visit o.projections - visit o.source - visit o.wheres - visit o.groups - visit o.windows - visit o.having + def visit_Arel_Nodes_SelectCore o, a + visit o.projections, a + visit o.source, a + visit o.wheres, a + visit o.groups, a + visit o.windows, a + visit o.having, a end - def visit_Arel_Nodes_SelectStatement o - visit o.cores - visit o.orders - visit o.limit - visit o.lock - visit o.offset + def visit_Arel_Nodes_SelectStatement o, a + visit o.cores, a + visit o.orders, a + visit o.limit, a + visit o.lock, a + visit o.offset, a end - def visit_Arel_Nodes_UpdateStatement o - visit o.relation - visit o.values - visit o.wheres - visit o.orders - visit o.limit + def visit_Arel_Nodes_UpdateStatement o, a + visit o.relation, a + visit o.values, a + visit o.wheres, a + visit o.orders, a + visit o.limit, a end - def visit_Array o - o.each { |i| visit i } + def visit_Array o, a + o.each { |i| visit i, a } end - def visit_Hash o - o.each { |k,v| visit(k); visit(v) } + def visit_Hash o, a + o.each { |k,v| visit(k, a); visit(v, a) } end end end |