Class: Cyrel::Clause::OrderBy
Overview
Represents an ORDER BY clause in a Cypher query.
Instance Attribute Summary collapse
-
#order_items ⇒ Object
readonly
Returns the value of attribute order_items.
Instance Method Summary collapse
-
#initialize(*order_items) ⇒ OrderBy
constructor
Initializes an ORDER BY clause.
-
#render(query) ⇒ String
Renders the ORDER BY clause.
-
#replace!(other_order_by) ⇒ Object
Merging ORDER BY typically replaces the existing order.
Constructor Details
#initialize(*order_items) ⇒ OrderBy
Initializes an ORDER BY clause.
16 17 18 19 |
# File 'lib/cyrel/clause/order_by.rb', line 16 def initialize(*order_items) @order_items = process_items(order_items) # Process the array of pairs directly raise ArgumentError, 'ORDER BY clause requires at least one order item.' if @order_items.empty? end |
Instance Attribute Details
#order_items ⇒ Object (readonly)
Returns the value of attribute order_items.
7 8 9 |
# File 'lib/cyrel/clause/order_by.rb', line 7 def order_items @order_items end |
Instance Method Details
#render(query) ⇒ String
Renders the ORDER BY clause.
24 25 26 27 28 29 30 31 32 |
# File 'lib/cyrel/clause/order_by.rb', line 24 def render(query) rendered_items = @order_items.map do |item| expression, direction = item rendered_expr = render_expression(expression, query) "#{rendered_expr} #{direction.to_s.upcase}" end.join(', ') "ORDER BY #{rendered_items}" end |
#replace!(other_order_by) ⇒ Object
Merging ORDER BY typically replaces the existing order.
36 37 38 39 |
# File 'lib/cyrel/clause/order_by.rb', line 36 def replace!(other_order_by) @order_items = other_order_by.order_items self end |