Module: ActiveRecord::Refined::AST

Defined in:
lib/active_record/refined/ast.rb

Defined Under Namespace

Modules: Aggregations, Arithmetics, Predications Classes: Aggregate, And, Arithmetic, ArrayPredicate, As, Cast, Column, Comparison, DatetimeValueFunction, DistinctFrom, Exists, Extract, Function, In, Like, Match, Node, Not, Or, Ordering, Predicate, Value

Constant Summary collapse

NAME =

Column aliases and function names are written into the SQL as given, where a value would have been quoted, so anything that is not a plain name is refused. Quoting them instead would need the model's adapter, which does not reach this far, and quoting with the wrong one would be a bug of its own -- MySQL does not read "x" as an identifier.

/[[:alpha:]_][[:alnum:]_$]*/
ALIAS_NAME =
/\A#{NAME}\z/
FUNCTION_NAME =
/\A#{NAME}(\.#{NAME})?\z/
TYPE_NAME =

A SQL type as cast writes it: words, at most parenthesized with lengths -- double precision, decimal(10,2).

/\A[[:alpha:]_][[:alnum:]_ ]*(\(\d+(, ?\d+)?\))?\z/

Class Method Summary collapse

Class Method Details

.check_name(name, pattern, what) ⇒ Object

Raises:

  • (ArgumentError)


16
17
18
19
# File 'lib/active_record/refined/ast.rb', line 16

def self.check_name(name, pattern, what)
  return name if pattern.match?(name.to_s)
  raise ArgumentError, "#{name.inspect} is not a plain #{what}"
end