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 Method Summary collapse

Methods inherited from Node

#as, #asc, #collate, #desc

Constructor Details

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

Returns a new instance of As.



1999
2000
2001
2002
2003
2004
2005
2006
2007
# File 'lib/active_record/refined/ast.rb', line 1999

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