diff options
author | Bryan Helmkamp <bryan@brynary.com> | 2009-05-17 14:46:08 -0400 |
---|---|---|
committer | Bryan Helmkamp <bryan@brynary.com> | 2009-05-17 14:46:08 -0400 |
commit | 892337509b2bd269920dc567bc48c6a28c7222d2 (patch) | |
tree | 442843e51bce0a9bda8b1a83d30252a39d37e2d3 /lib/arel/algebra | |
parent | b0a45d52fdb7d8ce564f4dc2013bc790f98f1da3 (diff) | |
download | rails-892337509b2bd269920dc567bc48c6a28c7222d2.tar.gz rails-892337509b2bd269920dc567bc48c6a28c7222d2.tar.bz2 rails-892337509b2bd269920dc567bc48c6a28c7222d2.zip |
removed function_sql in favor of polymorphism
Conflicts:
lib/arel/algebra/primitives/attribute.rb
lib/arel/algebra/primitives/expression.rb
spec/arel/unit/primitives/expression_spec.rb
Diffstat (limited to 'lib/arel/algebra')
-rw-r--r-- | lib/arel/algebra/primitives/attribute.rb | 10 | ||||
-rw-r--r-- | lib/arel/algebra/primitives/expression.rb | 18 |
2 files changed, 18 insertions, 10 deletions
diff --git a/lib/arel/algebra/primitives/attribute.rb b/lib/arel/algebra/primitives/attribute.rb index 5e216770e4..943c5b030e 100644 --- a/lib/arel/algebra/primitives/attribute.rb +++ b/lib/arel/algebra/primitives/attribute.rb @@ -109,23 +109,23 @@ module Arel module Expressions def count(distinct = false) - distinct ? Expression.new(self, "DISTINCT").count : Expression.new(self, "COUNT") + distinct ? Distinct.new(self).count : Count.new(self) end def sum - Expression.new(self, "SUM") + Sum.new(self) end def maximum - Expression.new(self, "MAX") + Maximum.new(self) end def minimum - Expression.new(self, "MIN") + Minimum.new(self) end def average - Expression.new(self, "AVG") + Average.new(self) end end include Expressions diff --git a/lib/arel/algebra/primitives/expression.rb b/lib/arel/algebra/primitives/expression.rb index b67a5e1f8e..989397720c 100644 --- a/lib/arel/algebra/primitives/expression.rb +++ b/lib/arel/algebra/primitives/expression.rb @@ -1,12 +1,12 @@ module Arel class Expression < Attribute - attributes :attribute, :function_sql, :alias, :ancestor + attributes :attribute, :alias, :ancestor deriving :== delegate :relation, :to => :attribute alias_method :name, :alias - def initialize(attribute, function_sql, aliaz = nil, ancestor = nil) - @attribute, @function_sql, @alias, @ancestor = attribute, function_sql, aliaz, ancestor + def initialize(attribute, aliaz = nil, ancestor = nil) + @attribute, @alias, @ancestor = attribute, aliaz, ancestor end def aggregation? @@ -15,11 +15,11 @@ module Arel module Transformations def as(aliaz) - Expression.new(attribute, function_sql, aliaz, self) + self.class.new(attribute, aliaz, self) end def bind(new_relation) - new_relation == relation ? self : Expression.new(attribute.bind(new_relation), function_sql, @alias, self) + new_relation == relation ? self : self.class.new(attribute.bind(new_relation), @alias, self) end def to_attribute @@ -28,4 +28,12 @@ module Arel end include Transformations end + + class Count < Expression; end + class Distinct < Expression; end + class Sum < Expression; end + class Maximum < Expression; end + class Minimum < Expression; end + class Average < Expression; end end + |