Class: Neo4j::Core::Traversal::CypherQuery

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/neo4j-core/traversal/traverser.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (CypherQuery) initialize(start_id, dir, types, query_hash = nil, &block)

A new instance of CypherQuery



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

def initialize(start_id, dir, types, query_hash=nil, &block)
  q = Neo4j::Cypher.query do
    n = node(start_id)
    next_nodes = case dir
                   when :outgoing then
                     n.outgoing(types)
                   when :incoming then
                     n.incoming(types)
                   when :both then
                     n.both(types)
                 end
    if block
      self.instance_exec(next_nodes, &block)
    else
      query_hash.each{|pair|  next_nodes[pair[0]] == pair[1]}.to_a  if query_hash
      next_nodes
    end
  end

  @query = q.to_s
  self.return_variable=q.return_names.last
end

Instance Attribute Details

- (Object) query

Returns the value of attribute query



7
8
9
# File 'lib/neo4j-core/traversal/traverser.rb', line 7

def query
  @query
end

- (Object) return_variable

Returns the value of attribute return_variable



7
8
9
# File 'lib/neo4j-core/traversal/traverser.rb', line 7

def return_variable
  @return_variable
end

Instance Method Details

- (Object) each



36
37
38
39
40
# File 'lib/neo4j-core/traversal/traverser.rb', line 36

def each
  Neo4j._query(to_s).each do |r|
    yield r[return_variable]
  end
end

- (Object) to_s



32
33
34
# File 'lib/neo4j-core/traversal/traverser.rb', line 32

def to_s
  @query.to_s
end