Class: Aspen::Renderers::CypherBaseRenderer

Inherits:
AbstractRenderer show all
Defined in:
lib/aspen/renderers/cypher_base_renderer.rb

Instance Attribute Summary

Attributes inherited from AbstractRenderer

#environment, #statements

Instance Method Summary collapse

Methods inherited from AbstractRenderer

#initialize

Constructor Details

This class inherits a constructor from AbstractRenderer

Instance Method Details

#nodes(input_statements) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/aspen/renderers/cypher_base_renderer.rb', line 14

def nodes(input_statements)
  input_statements.
    flat_map(&:nodes).
    map { |node| "MERGE #{node.to_cypher}" }.
    uniq.
    join("\n")
end

#relationships(input_statements) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/aspen/renderers/cypher_base_renderer.rb', line 22

def relationships(input_statements)
  input_statements.map do |statement|
    if statement.type == :custom
      statement.to_cypher.lines.map { |line| "MERGE #{line}" }.join()
    elsif statement.type == :vanilla
      "MERGE #{statement.to_cypher}"
    else
      raise ArgumentError, "Statement is the wrong type, expected Aspen::CustomStatemen or Aspen::Statement, but got #{statement.class}"
    end
  end.join("\n")
end

#renderObject



5
6
7
8
9
10
11
12
# File 'lib/aspen/renderers/cypher_base_renderer.rb', line 5

def render
  [
    nodes(statements),
    "\n\n",
    relationships(statements),
    "\n"
  ].join()
end