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/nodes/function.rb

43 lines
894 B
Ruby
Raw Normal View History

2010-09-08 19:23:15 -04:00
module Arel
module Nodes
class Function < Arel::Nodes::Node
2010-09-23 17:02:12 -04:00
include Arel::Expression
include Arel::Predications
2012-02-22 09:25:10 -05:00
include Arel::WindowPredications
attr_accessor :expressions, :alias, :distinct
2010-09-08 19:23:15 -04:00
def initialize expr, aliaz = nil
@expressions = expr
@alias = aliaz && SqlLiteral.new(aliaz)
@distinct = false
2010-09-08 19:23:15 -04:00
end
def as aliaz
self.alias = SqlLiteral.new(aliaz)
2010-09-08 19:23:15 -04:00
self
end
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