Class: Neo4j::Embedded::ResultWrapper
- Inherits:
-
Object
- Object
- Neo4j::Embedded::ResultWrapper
show all
- Includes:
- Enumerable
- Defined in:
- lib/neo4j-embedded/cypher_response.rb
Overview
Note:
The result is a once forward read only Enumerable, work if you need to read the result twice - use #to_a
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.
Defined Under Namespace
Classes: ResultsAlreadyConsumedException
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
The original result from the Neo4j Cypher Engine, once forward read only !.
-
#unwrapped ⇒ Object
readonly
The original result from the Neo4j Cypher Engine, once forward read only !.
Instance Method Summary
collapse
Constructor Details
#initialize(source, query, unwrapped = nil) ⇒ ResultWrapper
17
18
19
20
21
22
23
|
# File 'lib/neo4j-embedded/cypher_response.rb', line 17
def initialize(source, query, unwrapped = nil)
@source = source
@struct = Struct.new(*source.columns.to_a.map!(&:to_sym)) unless source.columns.empty?
@unread = true
@query = query
@unwrapped = unwrapped
end
|
Instance Attribute Details
#source ⇒ Object
15
16
17
|
# File 'lib/neo4j-embedded/cypher_response.rb', line 15
def source
@source
end
|
#unwrapped ⇒ Object
15
16
17
|
# File 'lib/neo4j-embedded/cypher_response.rb', line 15
def unwrapped
@unwrapped
end
|
Instance Method Details
#columns ⇒ Array<Symbol>
38
39
40
|
# File 'lib/neo4j-embedded/cypher_response.rb', line 38
def columns
@source.columns.map!(&:to_sym)
end
|
#each ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/neo4j-embedded/cypher_response.rb', line 46
def each
fail ResultsAlreadyConsumedException unless @unread
if block_given?
@source.each do |row|
yield(row.each_with_object(@struct.new) do |(column, value), result|
result[column.to_sym] = unwrap(value)
end)
end
else
Enumerator.new(self)
end
end
|
#error? ⇒ Boolean
42
43
44
|
# File 'lib/neo4j-embedded/cypher_response.rb', line 42
def error?
false
end
|
#inspect ⇒ Object
33
34
35
|
# File 'lib/neo4j-embedded/cypher_response.rb', line 33
def inspect
"Enumerable query: '#{@query}'"
end
|
#to_s ⇒ Object
25
26
27
|
# File 'lib/neo4j-embedded/cypher_response.rb', line 25
def to_s
@query
end
|
#unwrapped? ⇒ Boolean
29
30
31
|
# File 'lib/neo4j-embedded/cypher_response.rb', line 29
def unwrapped?
!!unwrapped
end
|