Class: Cyrel::Clause::Match
Overview
Represents a MATCH or OPTIONAL MATCH clause in a Cypher query.
Instance Attribute Summary collapse
-
#optional ⇒ Object
readonly
Returns the value of attribute optional.
-
#path_variable ⇒ Object
readonly
Returns the value of attribute path_variable.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
-
#initialize(pattern, optional: false, path_variable: nil) ⇒ Match
constructor
A new instance of Match.
-
#render(query) ⇒ String
Renders the MATCH or OPTIONAL MATCH clause.
Constructor Details
#initialize(pattern, optional: false, path_variable: nil) ⇒ Match
Returns a new instance of Match.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/cyrel/clause/match.rb', line 13 def initialize(pattern, optional: false, path_variable: nil) super() # Call super for Base initialization # Ensure pattern is a valid type unless pattern.is_a?(Cyrel::Pattern::Path) || pattern.is_a?(Cyrel::Pattern::Node) || pattern.is_a?(Cyrel::Pattern::Relationship) raise ArgumentError, "Match pattern must be a Cyrel::Pattern::Path, Node, or Relationship, got #{pattern.class}" end @pattern = pattern @optional = optional @path_variable = path_variable&.to_sym end |
Instance Attribute Details
#optional ⇒ Object (readonly)
Returns the value of attribute optional.
7 8 9 |
# File 'lib/cyrel/clause/match.rb', line 7 def optional @optional end |
#path_variable ⇒ Object (readonly)
Returns the value of attribute path_variable.
7 8 9 |
# File 'lib/cyrel/clause/match.rb', line 7 def path_variable @path_variable end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
7 8 9 |
# File 'lib/cyrel/clause/match.rb', line 7 def pattern @pattern end |
Instance Method Details
#render(query) ⇒ String
Renders the MATCH or OPTIONAL MATCH clause.
31 32 33 34 35 36 37 |
# File 'lib/cyrel/clause/match.rb', line 31 def render(query) keyword = @optional ? 'OPTIONAL MATCH' : 'MATCH' path_assignment = @path_variable ? "#{@path_variable} = " : '' pattern_string = @pattern.render(query) "#{keyword} #{path_assignment}#{pattern_string}" end |