diff options
Diffstat (limited to 'lib/arel/algebra/expression.rb')
-rw-r--r-- | lib/arel/algebra/expression.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/arel/algebra/expression.rb b/lib/arel/algebra/expression.rb new file mode 100644 index 0000000000..875498c282 --- /dev/null +++ b/lib/arel/algebra/expression.rb @@ -0,0 +1,43 @@ +module Arel + class Expression < Attribute + attributes :attribute, :alias, :ancestor + deriving :== + delegate :relation, :to => :attribute + alias_method :name, :alias + + def initialize(attribute, aliaz = nil, ancestor = nil) + @attribute, @alias, @ancestor = attribute, aliaz, ancestor + end + + def aggregation? + true + end + + def inspect + "<#{self.class.name} #{attribute.inspect}>" + end + + module Transformations + def as(aliaz) + self.class.new(attribute, aliaz, self) + end + + def bind(new_relation) + new_relation == relation ? self : self.class.new(attribute.bind(new_relation), @alias, self) + end + + def to_attribute(relation) + Attribute.new(relation, @alias, :ancestor => self) + end + 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 + |