2017-02-13 13:58:58 -05:00
|
|
|
# frozen_string_literal: true
|
2018-02-24 01:45:50 -05:00
|
|
|
|
2010-09-08 19:23:15 -04:00
|
|
|
module Arel
|
|
|
|
module Nodes
|
2016-10-04 18:28:49 -04:00
|
|
|
class Function < Arel::Nodes::NodeExpression
|
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
|
|
|
|
2018-02-24 01:45:50 -05:00
|
|
|
def initialize(expr, aliaz = nil)
|
2013-05-17 18:43:54 -04:00
|
|
|
super()
|
2010-09-08 19:23:15 -04:00
|
|
|
@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
|
|
|
|
|
2018-02-24 01:45:50 -05:00
|
|
|
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
|
|
|
|
|
2018-02-24 01:45:50 -05:00
|
|
|
def eql?(other)
|
2012-08-18 22:33:25 -04:00
|
|
|
self.class == other.class &&
|
|
|
|
self.expressions == other.expressions &&
|
|
|
|
self.alias == other.alias &&
|
|
|
|
self.distinct == other.distinct
|
|
|
|
end
|
2017-07-25 09:12:11 -04:00
|
|
|
alias :== :eql?
|
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
|