class Neo4j::Core::CypherSession::Responses::Driver
Attributes
results[R]
Public Class Methods
new(responses, options = {})
click to toggle source
# File lib/neo4j/core/cypher_session/responses/driver.rb 10 def initialize(responses, options = {}) 11 @wrap_level = options[:wrap_level] || Neo4j::Core::Config.wrapping_level 12 13 @results = responses.map(&method(:result_from_data)) 14 end
Public Instance Methods
result_from_data(entities_data)
click to toggle source
# File lib/neo4j/core/cypher_session/responses/driver.rb 16 def result_from_data(entities_data) 17 rows = entities_data.map do |entity_data| 18 wrap_value(entity_data.values) 19 end 20 21 Neo4j::Core::CypherSession::Result.new(entities_data.keys, rows) 22 end
wrap_by_level(none_proc)
click to toggle source
Calls superclass method
Neo4j::Core::CypherSession::Responses::Base#wrap_by_level
# File lib/neo4j/core/cypher_session/responses/driver.rb 24 def wrap_by_level(none_proc) 25 super(@wrap_level == :none ? none_proc.call : nil) 26 end
Private Instance Methods
wrap_node(node)
click to toggle source
In the future the ::Neo4j::Core::Node
should either monkey patch or wrap Neo4j::Driver:Types::Node to avoid multiple object creation. This is probably best done once the other adapters (http, embedded) are removed.
# File lib/neo4j/core/cypher_session/responses/driver.rb 32 def wrap_node(node) 33 wrap_by_level(-> { node.properties }) { ::Neo4j::Core::Node.new(node.id, node.labels, node.properties) } 34 end
wrap_path(path)
click to toggle source
# File lib/neo4j/core/cypher_session/responses/driver.rb 42 def wrap_path(path) 43 nodes = path.nodes 44 relationships = path.relationships 45 wrap_by_level(-> { nodes.zip(relationships).flatten.compact.map(&:properties) }) do 46 ::Neo4j::Core::Path.new(nodes.map(&method(:wrap_node)), 47 relationships.map(&method(:wrap_relationship)), 48 nil) # remove directions from Path, looks like unused 49 end 50 end
wrap_relationship(rel)
click to toggle source
# File lib/neo4j/core/cypher_session/responses/driver.rb 36 def wrap_relationship(rel) 37 wrap_by_level(-> { rel.properties }) do 38 ::Neo4j::Core::Relationship.new(rel.id, rel.type, rel.properties, rel.start_node_id, rel.end_node_id) 39 end 40 end
wrap_value(value)
click to toggle source
# File lib/neo4j/core/cypher_session/responses/driver.rb 52 def wrap_value(value) 53 if value.is_a? Array 54 value.map(&method(:wrap_value)) 55 elsif value.is_a? Hash 56 value.map { |key, val| [key, wrap_value(val)] }.to_h 57 elsif value.is_a? Neo4j::Driver::Types::Node 58 wrap_node(value) 59 elsif value.is_a? Neo4j::Driver::Types::Relationship 60 wrap_relationship(value) 61 elsif value.is_a? Neo4j::Driver::Types::Path 62 wrap_path(value) 63 else 64 value 65 end 66 end