Class: Cyrel::Clause::Where
Overview
Represents a WHERE clause in a Cypher query.
Instance Attribute Summary collapse
-
#conditions ⇒ Object
readonly
Returns the value of attribute conditions.
Instance Method Summary collapse
-
#initialize(*conditions) ⇒ Where
constructor
A new instance of Where.
-
#merge!(other_where) ⇒ Object
Merges conditions from another Where clause using AND.
-
#render(query) ⇒ String?
Renders the WHERE clause.
Constructor Details
#initialize(*conditions) ⇒ Where
Returns a new instance of Where.
11 12 13 |
# File 'lib/cyrel/clause/where.rb', line 11 def initialize(*conditions) @conditions = conditions.flatten.map { |cond| Expression.coerce(cond) } end |
Instance Attribute Details
#conditions ⇒ Object (readonly)
Returns the value of attribute conditions.
7 8 9 |
# File 'lib/cyrel/clause/where.rb', line 7 def conditions @conditions end |
Instance Method Details
#merge!(other_where) ⇒ Object
Merges conditions from another Where clause using AND.
36 37 38 39 |
# File 'lib/cyrel/clause/where.rb', line 36 def merge!(other_where) @conditions.concat(other_where.conditions) self end |
#render(query) ⇒ String?
Renders the WHERE clause. Combines multiple conditions using AND.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/cyrel/clause/where.rb', line 19 def render(query) return nil if @conditions.empty? # Combine conditions with AND if there are multiple combined_condition = if @conditions.length == 1 @conditions.first else # Build a balanced AND tree for potentially better readability/performance? # For now, simple left-associative AND is fine. @conditions.reduce { |memo, cond| Expression::Logical.new(memo, :AND, cond) } end "WHERE #{combined_condition.render(query)}" end |