diff options
Diffstat (limited to 'lib/arel')
-rw-r--r-- | lib/arel/nodes/binary.rb | 10 | ||||
-rw-r--r-- | lib/arel/nodes/function.rb | 7 | ||||
-rw-r--r-- | lib/arel/nodes/grouping.rb | 10 | ||||
-rw-r--r-- | lib/arel/nodes/node.rb | 10 | ||||
-rw-r--r-- | lib/arel/table.rb | 24 | ||||
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 1 |
6 files changed, 24 insertions, 38 deletions
diff --git a/lib/arel/nodes/binary.rb b/lib/arel/nodes/binary.rb index 090468adfa..cfa75909c5 100644 --- a/lib/arel/nodes/binary.rb +++ b/lib/arel/nodes/binary.rb @@ -7,16 +7,6 @@ module Arel @left = left @right = right end - - # FIXME: this method should go away. I don't like people calling - # to_sql on non-head nodes. This forces us to walk the AST until we - # can find a node that has a "relation" member. - # - # Maybe we should just use `Table.engine`? :'( - def to_sql - viz = Visitors::ToSql.new Table.engine - viz.accept self - end end end end diff --git a/lib/arel/nodes/function.rb b/lib/arel/nodes/function.rb index a1cd13d4d1..133dd66019 100644 --- a/lib/arel/nodes/function.rb +++ b/lib/arel/nodes/function.rb @@ -1,6 +1,6 @@ module Arel module Nodes - class Function + class Function < Arel::Nodes::Node include Arel::Expression attr_accessor :expressions, :alias @@ -13,11 +13,6 @@ module Arel self.alias = SqlLiteral.new(aliaz) self end - - def to_sql - viz = Visitors::ToSql.new Table.engine - viz.accept self - end end end end diff --git a/lib/arel/nodes/grouping.rb b/lib/arel/nodes/grouping.rb index 0af1df1f7a..d52671f169 100644 --- a/lib/arel/nodes/grouping.rb +++ b/lib/arel/nodes/grouping.rb @@ -6,16 +6,6 @@ module Arel def initialize expression @expr = expression end - - # FIXME: this method should go away. I don't like people calling - # to_sql on non-head nodes. This forces us to walk the AST until we - # can find a node that has a "relation" member. - # - # Maybe we should just use `Table.engine`? :'( - def to_sql - viz = Visitors::ToSql.new Table.engine - viz.accept self - end end end end diff --git a/lib/arel/nodes/node.rb b/lib/arel/nodes/node.rb index fd5ea410ea..91c0a32573 100644 --- a/lib/arel/nodes/node.rb +++ b/lib/arel/nodes/node.rb @@ -15,6 +15,16 @@ module Arel def and right Nodes::And.new self, right end + + # FIXME: this method should go away. I don't like people calling + # to_sql on non-head nodes. This forces us to walk the AST until we + # can find a node that has a "relation" member. + # + # Maybe we should just use `Table.engine`? :'( + def to_sql engine = Table.engine + viz = Visitors::ToSql.new engine + viz.accept self + end end end end diff --git a/lib/arel/table.rb b/lib/arel/table.rb index 025ef30e55..ba31e3183b 100644 --- a/lib/arel/table.rb +++ b/lib/arel/table.rb @@ -5,7 +5,7 @@ module Arel @engine = nil class << self; attr_accessor :engine; end - attr_reader :name, :engine, :aliases, :table_alias + attr_accessor :name, :engine, :aliases, :table_alias def initialize name, engine = Table.engine @name = name @@ -36,10 +36,6 @@ module Arel end end - def tm - SelectManager.new(@engine, self) - end - def from table SelectManager.new(@engine, table) end @@ -49,7 +45,7 @@ module Arel end def join relation, klass = Nodes::InnerJoin - return tm unless relation + return select_manager unless relation sm = SelectManager.new(@engine) case relation @@ -62,27 +58,27 @@ module Arel end def group *columns - tm.group(*columns) + select_manager.group(*columns) end def order *expr - tm.order(*expr) + select_manager.order(*expr) end def where condition - tm.where condition + select_manager.where condition end def project *things - tm.project(*things) + select_manager.project(*things) end def take amount - tm.take amount + select_manager.take amount end def having expr - tm.having expr + select_manager.having expr end def columns @@ -98,6 +94,10 @@ module Arel end private + def select_manager + SelectManager.new(@engine, self) + end + def attributes_for columns return nil unless columns diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index deb087b390..274a491f78 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -1,4 +1,5 @@ require 'bigdecimal' +require 'date' module Arel module Visitors |