Module: ActiveRecord::Refined::BlockSyntax
- Includes:
- AST::Arithmetics, AST::Predications
- Defined in:
- lib/active_record/refined.rb
Overview
What a symbol answers to inside a block. A symbol names a column
there -- :age is "users"."age" -- and the methods below build a
condition, an expression or an ordering from it. Every one of them is
a refinement, so it exists inside a where, select, having,
order, group, joins, update_all or upsert_all block and
nowhere else.
The comparisons and the rest of the conditions are listed under
AST::Predications, the arithmetic under AST::Arithmetics; a number
or a string in a block takes as too, for a literal in a select list
-- 0.as(:depth) -- and a number on the left of an operator builds the
same expression a column on the left would.
Instance Method Summary collapse
-
#[](column_name) ⇒ AST::Column
A column of another table:
:posts[:author_id]is"posts"."author_id", for a join condition or a query over a join. -
#as(alias_name, quote: true) ⇒ AST::As
The column under an alias:
AS "name". -
#asc ⇒ AST::Ordering
An ascending ordering, which takes
nulls_firstandnulls_last. -
#collate(name) ⇒ AST::Collate
The column under a collation, for a comparison or an ordering:
"name" COLLATE nocase. -
#desc ⇒ AST::Ordering
A descending ordering, which takes
nulls_firstandnulls_last.
Methods included from AST::Arithmetics
#&, #*, #+, #-, #/, #<<, #>>, #^, #|, #~
Methods included from AST::Predications
#!=, #!~, #<, #<=, #==, #=~, #>, #>=, #between?, #bury, #casecmp?, #contains?, #dig, #dig_text, #distinct_from?, #end_with?, #except, #false?, #ilike?, #in?, #include?, #intersect?, #key?, #keys, #like?, #member?, #not_between?, #not_distinct_from?, #not_false?, #not_ilike?, #not_in?, #not_like?, #not_null?, #not_true?, #null?, #start_with?, #subset?, #superset?, #true?, #when
Instance Method Details
#[](column_name) ⇒ AST::Column
A column of another table: :posts[:author_id] is
"posts"."author_id", for a join condition or a query over a join.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/active_record/refined.rb', line 71 refine Symbol do import_methods AST::Predications import_methods AST::Arithmetics def as(alias_name, quote: true) AST::As.new(self, alias_name, quote: quote) end def asc AST::Ordering.new(self, :asc) end def desc AST::Ordering.new(self, :desc) end def collate(name) AST::Collate.new(self, name) end def [](column_name) AST::Column.new(self, column_name) end end |
#as(alias_name, quote: true) ⇒ AST::As
The column under an alias: AS "name". The alias is quoted, so
the name asked for is the name that comes back on every adapter;
quote: false writes it bare, for a schema that wants the folding,
and then it has to be a plain name.
|
|
# File 'lib/active_record/refined.rb', line 29
|
#asc ⇒ AST::Ordering
An ascending ordering, which takes nulls_first and nulls_last.
|
|
# File 'lib/active_record/refined.rb', line 40
|
#collate(name) ⇒ AST::Collate
The column under a collation, for a comparison or an ordering:
"name" COLLATE nocase. The name is the database's own and not
portable; PostgreSQL quotes it, the others take it bare and refuse
one that is not a plain identifier.
|
|
# File 'lib/active_record/refined.rb', line 52
|
#desc ⇒ AST::Ordering
A descending ordering, which takes nulls_first and nulls_last.
|
|
# File 'lib/active_record/refined.rb', line 46
|