Class: Cyrel::Clause::Delete
Overview
Represents a DELETE or DETACH DELETE clause in a Cypher query.
Instance Attribute Summary collapse
-
#detach ⇒ Object
readonly
Returns the value of attribute detach.
-
#variables ⇒ Object
readonly
Returns the value of attribute variables.
Instance Method Summary collapse
-
#initialize(*variables, detach: false) ⇒ Delete
constructor
Initializes a DELETE clause.
-
#merge!(other_delete) ⇒ Object
Merges variables from another Delete clause.
-
#render(_query) ⇒ String
Renders the DELETE or DETACH DELETE clause.
Constructor Details
#initialize(*variables, detach: false) ⇒ Delete
Initializes a DELETE clause.
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
#detach ⇒ Object (readonly)
Returns the value of attribute detach.
7 8 9 |
# File 'lib/cyrel/clause/delete.rb', line 7 def detach @detach end |
#variables ⇒ Object (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.
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.
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 |