Class: ActiveRecord::Refined::AST::StringAggregate
- Includes:
- Predications, Windowing
- Defined in:
- lib/active_record/refined/ast.rb
Overview
The strings of a group joined into one, a separator between:
string_agg(:title, ", "), with .order for the order they are
joined in. Every family has it under a name of its own with the
ORDER BY in a place of its own, and Arel has no node for an ORDER BY
inside a call, so the dialect writes the call. A NULL is passed
over as by any aggregate, so the CASE that stands in for FILTER
means the same here and is not refused as the JSON aggregates' is.
Instance Method Summary collapse
-
#filter(condition = nil, &block) ⇒ AST::StringAggregate
FILTER (WHERE condition), as Aggregate#filter. -
#initialize(operand, separator, orders: [], condition: nil) ⇒ StringAggregate
constructor
A new instance of StringAggregate.
-
#order(*exprs) ⇒ AST::StringAggregate
The order the strings are joined in: columns, or orderings such as
:title.desc.
Methods included from Windowing
Methods included from 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
Methods inherited from Node
Constructor Details
#initialize(operand, separator, orders: [], condition: nil) ⇒ StringAggregate
Returns a new instance of StringAggregate.
1934 1935 1936 1937 1938 1939 1940 1941 1942 |
# File 'lib/active_record/refined/ast.rb', line 1934 def initialize(operand, separator, orders: [], condition: nil) unless separator.is_a?(::String) raise ArgumentError, "#{separator.inspect} is not a String separator" end @operand = operand @separator = separator @orders = orders @condition = condition end |
Instance Method Details
#filter(condition = nil, &block) ⇒ AST::StringAggregate
FILTER (WHERE condition), as Aggregate#filter.
1954 1955 1956 1957 |
# File 'lib/active_record/refined/ast.rb', line 1954 def filter(condition = nil, &block) StringAggregate.new(operand, separator, orders: orders, condition: Case.argument(:filter, condition, block)) end |
#order(*exprs) ⇒ AST::StringAggregate
The order the strings are joined in: columns, or orderings such as
:title.desc.
1947 1948 1949 1950 |
# File 'lib/active_record/refined/ast.rb', line 1947 def order(*exprs) raise ArgumentError, "order needs an expression" if exprs.empty? StringAggregate.new(operand, separator, orders: orders + exprs, condition: condition) end |