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 |
# File 'lib/cyrel/clause/match.rb', line 13 def initialize(pattern, optional: false, path_variable: nil) super() # Call super for Base initialization Cyrel::Pattern.assert_pattern!(pattern, 'Match') @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.
25 26 27 28 29 30 31 |
# File 'lib/cyrel/clause/match.rb', line 25 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 |