Class: Neo4j::Embedded::ResultWrapper
- Inherits:
-
Object
- Object
- Neo4j::Embedded::ResultWrapper
- 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 !.
Instance Method Summary collapse
-
#columns ⇒ Array<Symbol>
The columns in the query result.
- #each ⇒ Object
-
#initialize(source, query) ⇒ ResultWrapper
constructor
A new instance of ResultWrapper.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(source, query) ⇒ ResultWrapper
Returns a new instance of ResultWrapper.
17 18 19 20 21 22 |
# File 'lib/neo4j-embedded/cypher_response.rb', line 17 def initialize(source, query) @source = source @struct = Struct.new(*source.columns.to_a.map(&:to_sym)) @unread = true @query = query 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 |
Instance Method Details
#columns ⇒ Array<Symbol>
Returns the columns in the query result.
33 34 35 |
# File 'lib/neo4j-embedded/cypher_response.rb', line 33 def columns @source.columns.map(&:to_sym) end |
#each ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/neo4j-embedded/cypher_response.rb', line 37 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] = (value.respond_to?(:wrapper) ? value.wrapper : value) end) end else Enumerator.new(self) end end |
#inspect ⇒ Object
28 29 30 |
# File 'lib/neo4j-embedded/cypher_response.rb', line 28 def inspect "Enumerable query: '#{@query}'" end |
#to_s ⇒ Object
24 25 26 |
# File 'lib/neo4j-embedded/cypher_response.rb', line 24 def to_s @query end |