Class: Cyrel::Clause::Return
Overview
Represents a RETURN clause in a Cypher query.
Defined Under Namespace
Classes: RawIdentifier
Instance Attribute Summary collapse
-
#distinct ⇒ Object
readonly
Returns the value of attribute distinct.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Instance Method Summary collapse
-
#initialize(*items, distinct: false) ⇒ Return
constructor
Initializes a RETURN clause.
-
#merge!(other_return) ⇒ Object
Merges items from another Return clause.
-
#render(query) ⇒ String
Renders the RETURN clause.
Constructor Details
#initialize(*items, distinct: false) ⇒ Return
Initializes a RETURN clause.
14 15 16 17 18 |
# File 'lib/cyrel/clause/return.rb', line 14 def initialize(*items, distinct: false) @items = process_items(items.flatten) @distinct = distinct raise ArgumentError, 'RETURN clause requires at least one item.' if @items.empty? end |
Instance Attribute Details
#distinct ⇒ Object (readonly)
Returns the value of attribute distinct.
7 8 9 |
# File 'lib/cyrel/clause/return.rb', line 7 def distinct @distinct end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
7 8 9 |
# File 'lib/cyrel/clause/return.rb', line 7 def items @items end |
Instance Method Details
#merge!(other_return) ⇒ Object
Merges items from another Return clause. Simple concatenation, assumes user handles potential duplicates if needed.
32 33 34 35 36 37 38 39 |
# File 'lib/cyrel/clause/return.rb', line 32 def merge!(other_return) @items.concat(other_return.items) # Decide on distinct status - prioritize true if either has it? # Or maybe raise error if distinct statuses conflict? # For now, let's keep the original distinct status. # @distinct ||= other_return.distinct self end |
#render(query) ⇒ String
Renders the RETURN clause.
23 24 25 26 27 |
# File 'lib/cyrel/clause/return.rb', line 23 def render(query) distinct_str = @distinct ? 'DISTINCT ' : '' rendered_items = @items.map { |item| render_item(item, query) }.join(', ') "RETURN #{distinct_str}#{rendered_items}" end |