Class: Neo4j::Embedded::ResultWrapper
- Inherits:
-
Object
- Object
- Neo4j::Embedded::ResultWrapper
- Includes:
- Enumerable
- Defined in:
- lib/neo4j-embedded/cypher_response.rb
Overview
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
-
#columns ⇒ Array<Symbol>
The columns in the query result.
- #each ⇒ Object
-
#initialize(source, query, unwrapped = nil) ⇒ ResultWrapper
constructor
A new instance of ResultWrapper.
- #inspect ⇒ Object
- #to_s ⇒ Object
- #unwrapped? ⇒ Boolean
Constructor Details
#initialize(source, query, unwrapped = nil) ⇒ ResultWrapper
Returns a new instance of 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 (readonly)
Returns the original result from the Neo4j Cypher Engine, once forward read only !.
15 16 17 |
# File 'lib/neo4j-embedded/cypher_response.rb', line 15 def source @source end |
#unwrapped ⇒ Object (readonly)
Returns the original result from the Neo4j Cypher Engine, once forward read only !.
15 16 17 |
# File 'lib/neo4j-embedded/cypher_response.rb', line 15 def unwrapped @unwrapped end |
Instance Method Details
#columns ⇒ Array<Symbol>
Returns the columns in the query result.
38 39 40 |
# File 'lib/neo4j-embedded/cypher_response.rb', line 38 def columns @source.columns.map!(&:to_sym) end |
#each ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/neo4j-embedded/cypher_response.rb', line 42 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 |
#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 |