Permalink
Browse files

refactoring to a method

  • Loading branch information...
1 parent 65b55b8 commit 8ec1b8490a383fd0b7189ba05f550853fc37fa72 @tenderlove tenderlove committed May 11, 2011
Showing with 11 additions and 3 deletions.
  1. +11 −3 lib/arel/visitors/to_sql.rb
@@ -13,7 +13,7 @@ def initialize engine
end
def accept object
- Thread.current[:arel_visitors_to_sql_last_column] = nil
+ self.last_column = nil
@pool = @engine.connection_pool
@pool.with_connection do |conn|
@connection = conn
@@ -22,6 +22,14 @@ def accept object
end
private
+ def last_column= col
+ Thread.current[:arel_visitors_to_sql_last_column] = col
+ end
+
+ def last_column
+ Thread.current[:arel_visitors_to_sql_last_column]
+ end
+
def visit_Arel_Nodes_DeleteStatement o
[
"DELETE FROM #{visit o.relation}",
@@ -355,7 +363,7 @@ def visit_Arel_Nodes_UnqualifiedColumn o
end
def visit_Arel_Attributes_Attribute o
- Thread.current[:arel_visitors_to_sql_last_column] = column_for o
+ self.last_column = column_for o
join_name = o.relation.table_alias || o.relation.name
"#{quote_table_name join_name}.#{quote_column_name o.name}"
end
@@ -373,7 +381,7 @@ def literal o; o end
alias :visit_Bignum :literal
alias :visit_Fixnum :literal
- def quoted o; quote(o, Thread.current[:arel_visitors_to_sql_last_column]) end
+ def quoted o; quote(o, last_column) end
alias :visit_ActiveSupport_Multibyte_Chars :quoted
alias :visit_ActiveSupport_StringInquirer :quoted

0 comments on commit 8ec1b84

Please sign in to comment.