Class: ActiveRecord::Refined::AST::Aggregate

Inherits:
Node
  • Object
show all
Includes:
Arithmetics, Predications
Defined in:
lib/active_record/refined/ast.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Arithmetics

#*, #+, #-, #/

Methods included from Predications

#!=, #!~, #<, #<=, #==, #=~, #>, #>=, #between?, #casecmp?, #distinct_from?, #end_with?, #ilike?, #in?, #include?, #intersect?, #like?, #member?, #not_between?, #not_distinct_from?, #not_ilike?, #not_in?, #not_like?, #not_null?, #null?, #start_with?, #subset?, #superset?

Methods inherited from Node

#as, #asc, #desc

Constructor Details

#initialize(operand, function, distinct: false) ⇒ Aggregate

Returns a new instance of Aggregate.



341
342
343
344
345
346
347
348
349
350
351
# File 'lib/active_record/refined/ast.rb', line 341

def initialize(operand, function, distinct: false)
  if distinct && function != :count
    raise ArgumentError, "#{function} does not take distinct"
  end
  if distinct && operand == :*
    raise ArgumentError, "count(:*) does not take distinct; name a column"
  end
  @operand = operand
  @function = function
  @distinct = distinct
end

Instance Attribute Details

#distinctObject (readonly)

Returns the value of attribute distinct.



339
340
341
# File 'lib/active_record/refined/ast.rb', line 339

def distinct
  @distinct
end

#functionObject (readonly)

Returns the value of attribute function.



339
340
341
# File 'lib/active_record/refined/ast.rb', line 339

def function
  @function
end

#operandObject (readonly)

Returns the value of attribute operand.



339
340
341
# File 'lib/active_record/refined/ast.rb', line 339

def operand
  @operand
end

Instance Method Details

#to_arel(table) ⇒ Object



353
354
355
356
357
358
359
360
# File 'lib/active_record/refined/ast.rb', line 353

def to_arel(table)
  arel_operand = to_arel_operand(operand, table)
  if function == :count
    arel_operand.count(distinct)
  else
    arel_operand.public_send(function)
  end
end