Class: Cyrel::Clause::Delete

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

Overview

Represents a DELETE or DETACH DELETE clause in a Cypher query.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*variables, detach: false) ⇒ Delete

Initializes a DELETE clause.

Parameters:

  • variables (Array<Symbol, String>)

    An array of variable names (aliases) to delete.

  • detach (Boolean) (defaults to: false)

    Whether to use DETACH DELETE.

Raises:

  • (ArgumentError)


12
13
14
15
16
# File 'lib/cyrel/clause/delete.rb', line 12

def initialize(*variables, detach: false)
  @variables = variables.flatten.map(&:to_sym)
  @detach = detach
  raise ArgumentError, 'DELETE clause requires at least one variable.' if @variables.empty?
end

Instance Attribute Details

#detachObject (readonly)

Returns the value of attribute detach.



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

def detach
  @detach
end

#variablesObject (readonly)

Returns the value of attribute variables.



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

def variables
  @variables
end

Instance Method Details

#merge!(other_delete) ⇒ Object

Merges variables from another Delete clause. Note: Merging DETACH and non-DETACH might require specific rules. This implementation simply combines variables and uses the ‘detach` status of the clause being merged into. A more robust implementation might raise an error or prioritize DETACH if either is true.

Parameters:



33
34
35
36
37
38
# File 'lib/cyrel/clause/delete.rb', line 33

def merge!(other_delete)
  @variables.concat(other_delete.variables).uniq!
  # Decide on detach status - let's prioritize detach=true if either has it
  @detach ||= other_delete.detach
  self
end

#render(_query) ⇒ String

Renders the DELETE or DETACH DELETE clause.

Parameters:

  • _query (Cyrel::Query)

    The query object (unused for DELETE).

Returns:

  • (String)

    The Cypher string fragment for the clause.



21
22
23
24
25
# File 'lib/cyrel/clause/delete.rb', line 21

def render(_query)
  keyword = @detach ? 'DETACH DELETE' : 'DELETE'
  variable_list = @variables.join(', ')
  "#{keyword} #{variable_list}"
end