Class: ActiveRecord::Refined::AST::Over
- Includes:
- Arithmetics, Predications
- Defined in:
- lib/active_record/refined/ast.rb
Overview
A function with a window. The window is built by chaining, the way Arel's own is, and each method returns a new node rather than adding to this one, so a window can be finished more than one way.
Instance Attribute Summary collapse
-
#frame ⇒ Object
readonly
Returns the value of attribute frame.
-
#function ⇒ Object
readonly
Returns the value of attribute function.
-
#orders ⇒ Object
readonly
Returns the value of attribute orders.
-
#partitions ⇒ Object
readonly
Returns the value of attribute partitions.
Instance Method Summary collapse
-
#initialize(function, partitions = [], orders = [], frame = nil) ⇒ Over
constructor
A new instance of Over.
- #order(*exprs) ⇒ Object
- #partition(*exprs) ⇒ Object
- #range(bounds) ⇒ Object
- #rows(bounds) ⇒ Object
- #to_arel(table, model) ⇒ Object
Methods included from Arithmetics
#&, #*, #+, #-, #/, #<<, #>>, #^, #|, #~
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(function, partitions = [], orders = [], frame = nil) ⇒ Over
Returns a new instance of Over.
1397 1398 1399 1400 1401 1402 |
# File 'lib/active_record/refined/ast.rb', line 1397 def initialize(function, partitions = [], orders = [], frame = nil) @function = function @partitions = partitions @orders = orders @frame = frame end |
Instance Attribute Details
#frame ⇒ Object (readonly)
Returns the value of attribute frame.
1395 1396 1397 |
# File 'lib/active_record/refined/ast.rb', line 1395 def frame @frame end |
#function ⇒ Object (readonly)
Returns the value of attribute function.
1395 1396 1397 |
# File 'lib/active_record/refined/ast.rb', line 1395 def function @function end |
#orders ⇒ Object (readonly)
Returns the value of attribute orders.
1395 1396 1397 |
# File 'lib/active_record/refined/ast.rb', line 1395 def orders @orders end |
#partitions ⇒ Object (readonly)
Returns the value of attribute partitions.
1395 1396 1397 |
# File 'lib/active_record/refined/ast.rb', line 1395 def partitions @partitions end |
Instance Method Details
#order(*exprs) ⇒ Object
1409 1410 1411 1412 |
# File 'lib/active_record/refined/ast.rb', line 1409 def order(*exprs) raise ArgumentError, "order needs an expression" if exprs.empty? Over.new(function, partitions, orders + exprs, frame) end |
#partition(*exprs) ⇒ Object
1404 1405 1406 1407 |
# File 'lib/active_record/refined/ast.rb', line 1404 def partition(*exprs) raise ArgumentError, "partition needs an expression" if exprs.empty? Over.new(function, partitions + exprs, orders, frame) end |
#range(bounds) ⇒ Object
1418 1419 1420 |
# File 'lib/active_record/refined/ast.rb', line 1418 def range(bounds) Over.new(function, partitions, orders, framing(:range, bounds)) end |
#rows(bounds) ⇒ Object
1414 1415 1416 |
# File 'lib/active_record/refined/ast.rb', line 1414 def rows(bounds) Over.new(function, partitions, orders, framing(:rows, bounds)) end |
#to_arel(table, model) ⇒ Object
1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 |
# File 'lib/active_record/refined/ast.rb', line 1422 def to_arel(table, model) window = Arel::Nodes::Window.new partitions.each { |expr| window.partition(to_arel_operand(expr, table, model)) } orders.each { |expr| window.order(to_arel_operand(expr, table, model)) } frame_arel(window) if frame # The JSON aggregates cannot ride a window everywhere; the node # itself says where, once the adapter is known. function.check_window(model) if function.is_a?(JsonAggregate) # A window-only function refuses to build on its own; here is where # it is asked for the call itself. arel_function = function.is_a?(WindowFunction) ? function.call_arel(table, model) : function.to_arel(table, model) Arel::Nodes::Over.new(arel_function, window) end |