Class: Cyrel::Clause::Set

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

Overview

Represents a SET clause in a Cypher query. Used for setting properties or labels on nodes/relationships.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(assignments) ⇒ Set

Initializes a SET clause.

Parameters:

  • assignments (Hash, Array)
    • Hash: { variable_or_prop_access => value_expression, … } e.g., { Cyrel.prop(:n, :name) => “New Name”, Cyrel.prop(:r, :weight) => 10 } e.g., { n: { name: “New Name”, age: 30 } } # For SET n = properties or n = properties e.g., { Cyrel.plus(:n) => { name: “New Name” } } # For SET n = { name: … }

    • Array: [[variable, label_string], …] # For SET n:Label e.g., [[:n, “NewLabel”], [:m, “AnotherLabel”]]

    Note: Mixing hash and array styles in one call is not directly supported, use multiple SET clauses if needed.



19
20
21
# File 'lib/cyrel/clause/set.rb', line 19

def initialize(assignments)
  @assignments = process_assignments(assignments)
end

Instance Attribute Details

#assignmentsObject (readonly)

Returns the value of attribute assignments.



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

def assignments
  @assignments
end

Instance Method Details

#merge!(other_set) ⇒ Object

Merges assignments from another Set clause.

Parameters:



38
39
40
41
42
43
# File 'lib/cyrel/clause/set.rb', line 38

def merge!(other_set)
  # Simple concatenation, assumes no conflicting assignments on the same property.
  # More sophisticated merging might be needed depending on requirements.
  @assignments.concat(other_set.assignments)
  self
end

#render(query) ⇒ String?

Renders the SET clause.

Parameters:

  • query (Cyrel::Query)

    The query object for rendering expressions.

Returns:

  • (String, nil)

    The Cypher string fragment, or nil if no assignments exist.



26
27
28
29
30
31
32
33
34
# File 'lib/cyrel/clause/set.rb', line 26

def render(query)
  return nil if @assignments.empty?

  set_parts = @assignments.map do |assignment|
    render_assignment(assignment, query)
  end

  "SET #{set_parts.join(', ')}"
end