2010-09-08 19:23:15 -04:00
|
|
|
module Arel
|
|
|
|
module Nodes
|
2010-09-27 16:12:15 -04:00
|
|
|
class Function < Arel::Nodes::Node
|
2010-09-23 17:02:12 -04:00
|
|
|
include Arel::Expression
|
2011-05-27 17:21:40 -04:00
|
|
|
include Arel::Predications
|
2012-02-22 09:25:10 -05:00
|
|
|
include Arel::WindowPredications
|
2011-01-04 23:27:34 -05:00
|
|
|
attr_accessor :expressions, :alias, :distinct
|
2010-09-08 19:23:15 -04:00
|
|
|
|
|
|
|
def initialize expr, aliaz = nil
|
|
|
|
@expressions = expr
|
2011-04-29 14:27:45 -04:00
|
|
|
@alias = aliaz && SqlLiteral.new(aliaz)
|
2011-01-04 23:27:34 -05:00
|
|
|
@distinct = false
|
2010-09-08 19:23:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def as aliaz
|
2011-04-29 14:27:45 -04:00
|
|
|
self.alias = SqlLiteral.new(aliaz)
|
2010-09-08 19:23:15 -04:00
|
|
|
self
|
|
|
|
end
|
2012-08-18 22:33:25 -04:00
|
|
|
|
|
|
|
def hash
|
|
|
|
[@expressions, @alias, @distinct].hash
|
|
|
|
end
|
|
|
|
|
|
|
|
def eql? other
|
|
|
|
self.class == other.class &&
|
|
|
|
self.expressions == other.expressions &&
|
|
|
|
self.alias == other.alias &&
|
|
|
|
self.distinct == other.distinct
|
|
|
|
end
|
2010-09-08 19:23:15 -04:00
|
|
|
end
|
2010-12-15 00:06:16 -05:00
|
|
|
|
|
|
|
%w{
|
|
|
|
Sum
|
|
|
|
Exists
|
|
|
|
Max
|
|
|
|
Min
|
|
|
|
Avg
|
|
|
|
}.each do |name|
|
|
|
|
const_set(name, Class.new(Function))
|
|
|
|
end
|
2010-09-08 19:23:15 -04:00
|
|
|
end
|
|
|
|
end
|