Class: Neo4j::Cypher::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/neo4j-cypher/result.rb

Overview

Generates a Cypher string from a Ruby DSL The result returned by #to_s and the last Cypher return columns can be found #return_names. The cypher query will only be generated once - in the constructor.

Instance Method Summary collapse

Constructor Details

#initialize(*args, &dsl_block) ⇒ Result

Returns a new instance of Result.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/neo4j-cypher/result.rb', line 9

def initialize(*args, &dsl_block)
  @root = Neo4j::Cypher::RootClause.new
  eval_context = @root.eval_context
  to_dsl_args = args.map do |a|
    case
      when a.is_a?(Array) && a.first.respond_to?(:_java_node)
        eval_context.node(*a)
      when a.is_a?(Array) && a.first.respond_to?(:_java_rel)
        eval_context.rel(*a)
      when a.respond_to?(:_java_node)
        eval_context.node(a)
      when a.respond_to?(:_java_rel)
        eval_context.rel(a)
      else
        raise "Illegal argument #{a.class}"
    end

  end
  @root.execute(to_dsl_args, &dsl_block)
  @result = @root.return_value
end

Instance Method Details

#return_namesObject



31
32
33
# File 'lib/neo4j-cypher/result.rb', line 31

def return_names
  @root.return_names
end

#to_sObject

Converts the DSL query to a cypher String which can be executed by cypher query engine.



36
37
38
# File 'lib/neo4j-cypher/result.rb', line 36

def to_s
  @result
end