Class: Neo4j::Cypher::ResultWrapper

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/neo4j-cypher/result_wrapper.rb

Overview

Wraps the Cypher query result. Loads the node and relationships wrapper if possible and use symbol as column keys. This is typically used in the native neo4j bindings since result does is not a Ruby enumerable with symbols as keys.

Examples:

result = Neo4j.query(@a, @b){|a,b| node(a,b).as(:n)}
r = @query_result.to_a # can only loop once
r.size.should == 2
r.first.should include(:n)
r[0][:n].neo_id.should == @a.neo_id
r[1][:n].neo_id.should == @b.neo_id

Defined Under Namespace

Classes: ResultsAlreadyConsumedException

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ ResultWrapper

Returns a new instance of ResultWrapper.



23
24
25
26
# File 'lib/neo4j-cypher/result_wrapper.rb', line 23

def initialize(source)
  @source = source
  @unread = true
end

Instance Attribute Details

#sourceObject (readonly)

Returns the original result from the Neo4j Cypher Engine, once forward read only !.

Returns:

  • the original result from the Neo4j Cypher Engine, once forward read only !



21
22
23
# File 'lib/neo4j-cypher/result_wrapper.rb', line 21

def source
  @source
end

Instance Method Details

#columnsArray<Symbol>

Returns the columns in the query result.

Returns:

  • (Array<Symbol>)

    the columns in the query result



29
30
31
# File 'lib/neo4j-cypher/result_wrapper.rb', line 29

def columns
  @source.columns.map { |x| x.to_sym }
end

#eachObject

for the Enumerable contract



34
35
36
37
38
39
40
41
42
43
# File 'lib/neo4j-cypher/result_wrapper.rb', line 34

def each
  raise ResultsAlreadyConsumedException unless @unread

  if block_given?
    @unread = false
    @source.each { |row| yield symbolize_row_keys(row) }
  else
    Enumerator.new(self)
  end
end