2008-04-18 15:59:29 -04:00
|
|
|
module Arel
|
2008-02-16 19:09:37 -05:00
|
|
|
class Expression < Attribute
|
2009-05-17 14:46:08 -04:00
|
|
|
attributes :attribute, :alias, :ancestor
|
2008-05-19 22:38:36 -04:00
|
|
|
deriving :==
|
2008-02-04 01:10:38 -05:00
|
|
|
delegate :relation, :to => :attribute
|
2008-02-16 19:09:37 -05:00
|
|
|
alias_method :name, :alias
|
2009-04-23 17:53:03 -04:00
|
|
|
|
2009-05-17 14:46:08 -04:00
|
|
|
def initialize(attribute, aliaz = nil, ancestor = nil)
|
|
|
|
@attribute, @alias, @ancestor = attribute, aliaz, ancestor
|
2008-02-04 01:10:38 -05:00
|
|
|
end
|
2009-04-23 17:53:03 -04:00
|
|
|
|
2008-04-13 21:45:20 -04:00
|
|
|
def aggregation?
|
|
|
|
true
|
|
|
|
end
|
2009-04-23 17:53:03 -04:00
|
|
|
|
2009-05-18 01:49:50 -04:00
|
|
|
def inspect
|
|
|
|
"<#{self.class.name} #{attribute.inspect}>"
|
|
|
|
end
|
|
|
|
|
2008-05-16 15:32:59 -04:00
|
|
|
module Transformations
|
|
|
|
def as(aliaz)
|
2009-05-17 14:46:08 -04:00
|
|
|
self.class.new(attribute, aliaz, self)
|
2008-05-16 15:32:59 -04:00
|
|
|
end
|
2009-04-23 17:53:03 -04:00
|
|
|
|
2008-05-16 15:32:59 -04:00
|
|
|
def bind(new_relation)
|
2009-05-17 14:46:08 -04:00
|
|
|
new_relation == relation ? self : self.class.new(attribute.bind(new_relation), @alias, self)
|
2008-05-16 15:32:59 -04:00
|
|
|
end
|
2009-04-23 17:53:03 -04:00
|
|
|
|
2008-05-27 17:37:11 -04:00
|
|
|
def to_attribute(relation)
|
2008-05-16 15:32:59 -04:00
|
|
|
Attribute.new(relation, @alias, :ancestor => self)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
include Transformations
|
2008-02-04 01:10:38 -05:00
|
|
|
end
|
2009-05-17 14:46:08 -04:00
|
|
|
|
|
|
|
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
|
2009-05-17 14:46:08 -04:00
|
|
|
|