Class: Cyrel::Clause::Return

Inherits:
Base
  • Object
show all
Defined in:
lib/cyrel/clause/return.rb

Overview

Represents a RETURN clause in a Cypher query.

Defined Under Namespace

Classes: RawIdentifier

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*items, distinct: false) ⇒ Return

Initializes a RETURN clause.

Parameters:

  • items (Array<Cyrel::Expression::Base, Object, String, Symbol>)

    Items to return. Non-Expression objects are coerced. Strings/Symbols can represent variables or simple property access (though Expressions are preferred).

  • distinct (Boolean) (defaults to: false)

    Whether to return distinct results.

Raises:

  • (ArgumentError)


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

#distinctObject (readonly)

Returns the value of attribute distinct.



7
8
9
# File 'lib/cyrel/clause/return.rb', line 7

def distinct
  @distinct
end

#itemsObject (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.

Parameters:



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.

Parameters:

  • query (Cyrel::Query)

    The query object for rendering expressions.

Returns:

  • (String)

    The Cypher string fragment for the 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