Class: ActiveRecord::Refined::AST::As

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

Overview

A column alias, quoted by the adapter, so that the name asked for is the name that comes back: unquoted, PostgreSQL folds a capital away and the other two keep it, which is one block meaning two things. Quoting also leaves nothing to refuse -- a name that would have been SQL is an identifier with a strange name instead.

quote: false asks for the name as written, for a schema that wants the folding.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#as, #asc, #desc

Constructor Details

#initialize(operand, alias_name, quote: true) ⇒ As

Returns a new instance of As.



979
980
981
982
983
984
985
986
987
# File 'lib/active_record/refined/ast.rb', line 979

def initialize(operand, alias_name, quote: true)
  # Checked here rather than where the SQL is built, so that a name
  # the adapter is not being asked to quote is refused where it was
  # written.
  AST.check_name(alias_name, ALIAS_NAME, "column alias") unless quote
  @operand = operand
  @alias_name = alias_name
  @quote = quote
end

Instance Attribute Details

#alias_nameObject (readonly)

Returns the value of attribute alias_name.



977
978
979
# File 'lib/active_record/refined/ast.rb', line 977

def alias_name
  @alias_name
end

#operandObject (readonly)

Returns the value of attribute operand.



977
978
979
# File 'lib/active_record/refined/ast.rb', line 977

def operand
  @operand
end

#quoteObject (readonly)

Returns the value of attribute quote.



977
978
979
# File 'lib/active_record/refined/ast.rb', line 977

def quote
  @quote
end

Instance Method Details

#to_arel(table, model) ⇒ Object



989
990
991
# File 'lib/active_record/refined/ast.rb', line 989

def to_arel(table, model)
  to_arel_operand(operand, table, model).as(alias_sql(model))
end