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

45 lines
912 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2018-02-24 01:45:50 -05:00
2010-09-08 19:23:15 -04:00
module Arel
module Nodes
class Function < Arel::Nodes::NodeExpression
2012-02-22 09:25:10 -05:00
include Arel::WindowPredications
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
@alias = aliaz && SqlLiteral.new(aliaz)
@distinct = false
2010-09-08 19:23:15 -04:00
end
2018-02-24 01:45:50 -05:00
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
2018-02-24 01:45:50 -05:00
def eql?(other)
self.class == other.class &&
self.expressions == other.expressions &&
self.alias == other.alias &&
self.distinct == other.distinct
end
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