1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/lib/arel/algebra/primitives/expression.rb

40 lines
949 B
Ruby
Raw Normal View History

module Arel
class Expression < Attribute
attributes :attribute, :alias, :ancestor
2008-05-19 22:38:36 -04:00
deriving :==
delegate :relation, :to => :attribute
alias_method :name, :alias
2009-04-23 17:53:03 -04:00
def initialize(attribute, aliaz = nil, ancestor = nil)
@attribute, @alias, @ancestor = attribute, aliaz, ancestor
end
2009-04-23 17:53:03 -04:00
def aggregation?
true
end
2009-04-23 17:53:03 -04:00
module Transformations
def as(aliaz)
self.class.new(attribute, aliaz, self)
end
2009-04-23 17:53:03 -04:00
def bind(new_relation)
new_relation == relation ? self : self.class.new(attribute.bind(new_relation), @alias, self)
end
2009-04-23 17:53:03 -04:00
def to_attribute
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
2009-04-23 17:53:03 -04:00
end