Class: Cyrel::Clause::Call

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

Overview

Represents a standalone CALL procedure clause. Example: CALL db.labels() YIELD label WHERE label STARTS WITH ‘X’ RETURN label

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(procedure_name, arguments: [], yield_items: nil, where: nil, return_items: nil) ⇒ Call

Returns a new instance of Call.

Parameters:

  • procedure_name (String)

    The name of the procedure (e.g., “db.labels”).

  • arguments (Array) (defaults to: [])

    Arguments to pass to the procedure (will be parameterized).

  • yield_items (Array<String>, String, nil) (defaults to: nil)

    Raw string(s) for the YIELD part (e.g., “label”, [“id”, “name AS nodeName”]).

  • where_clause (Cyrel::Clause::Where, nil)

    Optional WHERE clause applied after YIELD.

  • return_clause (Cyrel::Clause::Return, nil)

    Optional RETURN clause applied after WHERE/YIELD.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cyrel/clause/call.rb', line 15

def initialize(procedure_name, arguments: [], yield_items: nil, where: nil, return_items: nil)
  @procedure_name = procedure_name
  @arguments = arguments # Store raw arguments, parameterize during render
  @yield_items = yield_items ? Array(yield_items).join(', ') : nil # Simple string join for now

  @where_clause = case where
                  when Clause::Where then where
                  when nil then nil
                  else Clause::Where.new(*Array(where)) # Coerce Hash/Array/Expression
                  end

  @return_clause = case return_items
                   when Clause::Return then return_items
                   when nil then nil
                   else Clause::Return.new(*Array(return_items))
                   end
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



8
9
10
# File 'lib/cyrel/clause/call.rb', line 8

def arguments
  @arguments
end

#procedure_nameObject (readonly)

Returns the value of attribute procedure_name.



8
9
10
# File 'lib/cyrel/clause/call.rb', line 8

def procedure_name
  @procedure_name
end

#return_clauseObject (readonly)

Returns the value of attribute return_clause.



8
9
10
# File 'lib/cyrel/clause/call.rb', line 8

def return_clause
  @return_clause
end

#where_clauseObject (readonly)

Returns the value of attribute where_clause.



8
9
10
# File 'lib/cyrel/clause/call.rb', line 8

def where_clause
  @where_clause
end

#yield_itemsObject (readonly)

Returns the value of attribute yield_items.



8
9
10
# File 'lib/cyrel/clause/call.rb', line 8

def yield_items
  @yield_items
end

Instance Method Details

#render(query) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cyrel/clause/call.rb', line 33

def render(query)
  rendered_args = @arguments.map { |arg| Expression.coerce(arg).render(query) }.join(', ')
  call_part = "CALL #{@procedure_name}(#{rendered_args})"
  yield_part = @yield_items ? " YIELD #{@yield_items}" : ''
  where_part = @where_clause ? " #{@where_clause.render(query)}" : '' # Render WHERE clause
  return_part = @return_clause ? " #{@return_clause.render(query)}" : '' # Render RETURN clause

  # Ensure correct ordering and spacing
  parts = [call_part, yield_part, where_part, return_part]
  parts.compact.reject(&:empty?).join # Join non-empty parts without extra spaces
end