Class: Cyrel::Clause::Unwind
Overview
UNWIND clause for expanding lists into rows Like unpacking a suitcase, but for data and with less wrinkled clothes
Instance Attribute Summary collapse
-
#expression ⇒ Object
readonly
Returns the value of attribute expression.
-
#variable ⇒ Object
readonly
Returns the value of attribute variable.
Instance Method Summary collapse
-
#initialize(expression, variable) ⇒ Unwind
constructor
A new instance of Unwind.
- #render(query) ⇒ Object
Constructor Details
#initialize(expression, variable) ⇒ Unwind
Returns a new instance of Unwind.
10 11 12 13 |
# File 'lib/cyrel/clause/unwind.rb', line 10 def initialize(expression, variable) @expression = expression @variable = variable.to_sym end |
Instance Attribute Details
#expression ⇒ Object (readonly)
Returns the value of attribute expression.
8 9 10 |
# File 'lib/cyrel/clause/unwind.rb', line 8 def expression @expression end |
#variable ⇒ Object (readonly)
Returns the value of attribute variable.
8 9 10 |
# File 'lib/cyrel/clause/unwind.rb', line 8 def variable @variable end |
Instance Method Details
#render(query) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cyrel/clause/unwind.rb', line 15 def render(query) cypher_parts = ['UNWIND'] # Handle the expression expr_str = case @expression when Symbol # It's a parameter param_key = query.register_parameter(@expression) "$#{param_key}" when Array # Literal array "[#{@expression.map { |item| render_array_item(item, query) }.join(', ')}]" when Expression::Base # It's already an expression @expression.render(query) else # Try to coerce it Expression.coerce(@expression).render(query) end cypher_parts << expr_str cypher_parts << 'AS' cypher_parts << @variable.to_s cypher_parts.join(' ') end |