neography-down 1.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.project +12 -0
- data/.rspec +1 -0
- data/.travis.yml +4 -0
- data/CHANGELOG.md +939 -0
- data/CONTRIBUTORS +18 -0
- data/Gemfile +4 -0
- data/Guardfile +14 -0
- data/LICENSE +19 -0
- data/README.md +281 -0
- data/Rakefile +14 -0
- data/examples/facebook.rb +40 -0
- data/examples/facebook_v2.rb +25 -0
- data/examples/greatest.rb +43 -0
- data/examples/linkedin.rb +39 -0
- data/examples/linkedin_v2.rb +22 -0
- data/examples/traversal_example1.rb +65 -0
- data/examples/traversal_example2.rb +54 -0
- data/lib/neography.rb +45 -0
- data/lib/neography/config.rb +64 -0
- data/lib/neography/connection.rb +263 -0
- data/lib/neography/equal.rb +21 -0
- data/lib/neography/errors.rb +60 -0
- data/lib/neography/index.rb +52 -0
- data/lib/neography/multi_json_parser.rb +28 -0
- data/lib/neography/neography.rb +10 -0
- data/lib/neography/node.rb +63 -0
- data/lib/neography/node_path.rb +29 -0
- data/lib/neography/node_relationship.rb +37 -0
- data/lib/neography/node_traverser.rb +146 -0
- data/lib/neography/path_traverser.rb +100 -0
- data/lib/neography/property.rb +110 -0
- data/lib/neography/property_container.rb +28 -0
- data/lib/neography/railtie.rb +19 -0
- data/lib/neography/relationship.rb +78 -0
- data/lib/neography/relationship_traverser.rb +80 -0
- data/lib/neography/rest.rb +99 -0
- data/lib/neography/rest/batch.rb +414 -0
- data/lib/neography/rest/clean.rb +17 -0
- data/lib/neography/rest/constraints.rb +38 -0
- data/lib/neography/rest/cypher.rb +29 -0
- data/lib/neography/rest/extensions.rb +21 -0
- data/lib/neography/rest/gremlin.rb +20 -0
- data/lib/neography/rest/helpers.rb +96 -0
- data/lib/neography/rest/node_auto_indexes.rb +60 -0
- data/lib/neography/rest/node_indexes.rb +139 -0
- data/lib/neography/rest/node_labels.rb +49 -0
- data/lib/neography/rest/node_paths.rb +49 -0
- data/lib/neography/rest/node_properties.rb +52 -0
- data/lib/neography/rest/node_relationships.rb +33 -0
- data/lib/neography/rest/node_traversal.rb +25 -0
- data/lib/neography/rest/nodes.rb +94 -0
- data/lib/neography/rest/other_node_relationships.rb +38 -0
- data/lib/neography/rest/relationship_auto_indexes.rb +60 -0
- data/lib/neography/rest/relationship_indexes.rb +142 -0
- data/lib/neography/rest/relationship_properties.rb +52 -0
- data/lib/neography/rest/relationship_types.rb +11 -0
- data/lib/neography/rest/relationships.rb +16 -0
- data/lib/neography/rest/schema_indexes.rb +26 -0
- data/lib/neography/rest/spatial.rb +137 -0
- data/lib/neography/rest/transactions.rb +101 -0
- data/lib/neography/tasks.rb +207 -0
- data/lib/neography/version.rb +3 -0
- data/neography.gemspec +39 -0
- data/spec/integration/authorization_spec.rb +40 -0
- data/spec/integration/broken_spatial_spec.rb +28 -0
- data/spec/integration/index_spec.rb +71 -0
- data/spec/integration/neography_spec.rb +10 -0
- data/spec/integration/node_encoding_spec.rb +71 -0
- data/spec/integration/node_path_spec.rb +222 -0
- data/spec/integration/node_relationship_spec.rb +381 -0
- data/spec/integration/node_spec.rb +260 -0
- data/spec/integration/parsing_spec.rb +13 -0
- data/spec/integration/performance_spec.rb +17 -0
- data/spec/integration/relationship_spec.rb +37 -0
- data/spec/integration/rest_batch_no_streaming_spec.rb +41 -0
- data/spec/integration/rest_batch_spec.rb +604 -0
- data/spec/integration/rest_batch_streaming_spec.rb +51 -0
- data/spec/integration/rest_bulk_spec.rb +106 -0
- data/spec/integration/rest_constraints_spec.rb +72 -0
- data/spec/integration/rest_experimental_spec.rb +22 -0
- data/spec/integration/rest_gremlin_fail_spec.rb +46 -0
- data/spec/integration/rest_header_spec.rb +15 -0
- data/spec/integration/rest_index_spec.rb +481 -0
- data/spec/integration/rest_labels_spec.rb +128 -0
- data/spec/integration/rest_node_spec.rb +274 -0
- data/spec/integration/rest_other_node_relationship_spec.rb +137 -0
- data/spec/integration/rest_path_spec.rb +231 -0
- data/spec/integration/rest_plugin_spec.rb +177 -0
- data/spec/integration/rest_relationship_spec.rb +354 -0
- data/spec/integration/rest_relationship_types_spec.rb +18 -0
- data/spec/integration/rest_schema_index_spec.rb +32 -0
- data/spec/integration/rest_spatial_spec.rb +166 -0
- data/spec/integration/rest_transaction_spec.rb +166 -0
- data/spec/integration/rest_traverse_spec.rb +149 -0
- data/spec/integration/unmanaged_spec.rb +27 -0
- data/spec/matchers.rb +33 -0
- data/spec/neography_spec.rb +23 -0
- data/spec/spec_helper.rb +44 -0
- data/spec/unit/config_spec.rb +135 -0
- data/spec/unit/connection_spec.rb +284 -0
- data/spec/unit/node_spec.rb +100 -0
- data/spec/unit/properties_spec.rb +285 -0
- data/spec/unit/relationship_spec.rb +118 -0
- data/spec/unit/rest/batch_spec.rb +262 -0
- data/spec/unit/rest/clean_spec.rb +16 -0
- data/spec/unit/rest/constraints_spec.rb +45 -0
- data/spec/unit/rest/cypher_spec.rb +20 -0
- data/spec/unit/rest/extensions_spec.rb +28 -0
- data/spec/unit/rest/gremlin_spec.rb +25 -0
- data/spec/unit/rest/helpers_spec.rb +124 -0
- data/spec/unit/rest/labels_spec.rb +77 -0
- data/spec/unit/rest/node_auto_indexes_spec.rb +70 -0
- data/spec/unit/rest/node_indexes_spec.rb +140 -0
- data/spec/unit/rest/node_paths_spec.rb +77 -0
- data/spec/unit/rest/node_properties_spec.rb +79 -0
- data/spec/unit/rest/node_relationships_spec.rb +57 -0
- data/spec/unit/rest/node_traversal_spec.rb +35 -0
- data/spec/unit/rest/nodes_spec.rb +187 -0
- data/spec/unit/rest/relationship_auto_indexes_spec.rb +66 -0
- data/spec/unit/rest/relationship_indexes_spec.rb +132 -0
- data/spec/unit/rest/relationship_properties_spec.rb +79 -0
- data/spec/unit/rest/relationship_types_spec.rb +15 -0
- data/spec/unit/rest/relationships_spec.rb +21 -0
- data/spec/unit/rest/schema_index_spec.rb +30 -0
- data/spec/unit/rest/transactions_spec.rb +43 -0
- metadata +372 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Neography
|
|
2
|
+
|
|
3
|
+
# == This mixin is used for both nodes and relationships to decide if two entities are equal or not.
|
|
4
|
+
#
|
|
5
|
+
module Equal
|
|
6
|
+
def equal?(o)
|
|
7
|
+
eql?(o)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def eql?(o)
|
|
11
|
+
return false unless o.respond_to?(:neo_id)
|
|
12
|
+
o.neo_id == neo_id
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def ==(o)
|
|
16
|
+
eql?(o)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
module Neography
|
|
2
|
+
|
|
3
|
+
class NeographyError < StandardError
|
|
4
|
+
attr_reader :message, :code, :stacktrace, :request, :index
|
|
5
|
+
|
|
6
|
+
def initialize(message = nil, code = nil, stacktrace = nil, request = nil, index = 0)
|
|
7
|
+
@message = message
|
|
8
|
+
@code = code
|
|
9
|
+
@stacktrace = stacktrace
|
|
10
|
+
@request = request
|
|
11
|
+
@index = index
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def to_s
|
|
16
|
+
"NeographyError: \n--message: #{@message}, \n--code: #{@code}, \n--stacktrace: #{@stacktrace}, \n--request: #{@request}, \n--index: #{@index}"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# HTTP Authentication error
|
|
20
|
+
class UnauthorizedError < NeographyError; end
|
|
21
|
+
|
|
22
|
+
# the Neo4j server Exceptions returned by the REST API:
|
|
23
|
+
|
|
24
|
+
# A node could not be found
|
|
25
|
+
class NodeNotFoundException < NeographyError; end
|
|
26
|
+
|
|
27
|
+
# A node cannot be deleted because it has relationships
|
|
28
|
+
class OperationFailureException < NeographyError; end
|
|
29
|
+
|
|
30
|
+
# Properties can not be null
|
|
31
|
+
class PropertyValueException < NeographyError; end
|
|
32
|
+
|
|
33
|
+
# Trying to a delete a property that does not exist
|
|
34
|
+
class NoSuchPropertyException < NeographyError; end
|
|
35
|
+
|
|
36
|
+
# A relationship could not be found
|
|
37
|
+
class RelationshipNotFoundException < NeographyError; end
|
|
38
|
+
|
|
39
|
+
# Error during valid Cypher query
|
|
40
|
+
class BadInputException < NeographyError; end
|
|
41
|
+
|
|
42
|
+
# Invalid Cypher query syntax
|
|
43
|
+
class SyntaxException < NeographyError; end
|
|
44
|
+
|
|
45
|
+
# A path could not be found by node traversal
|
|
46
|
+
class NotFoundException < NeographyError; end
|
|
47
|
+
|
|
48
|
+
# Thrown when CREATE UNIQUE matches multiple paths.
|
|
49
|
+
class UniquePathNotUniqueException < NeographyError; end
|
|
50
|
+
|
|
51
|
+
# Signals that a deadlock between two or more transactions has been detected
|
|
52
|
+
class DeadlockDetectedException < NeographyError; end
|
|
53
|
+
|
|
54
|
+
# Unknown batch option exception detected
|
|
55
|
+
class UnknownBatchOptionException < NeographyError; end
|
|
56
|
+
|
|
57
|
+
# A Cypher query is using a parameter that is not supplied
|
|
58
|
+
class ParameterNotFoundException < NeographyError; end
|
|
59
|
+
|
|
60
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
module Neography
|
|
2
|
+
module Index
|
|
3
|
+
|
|
4
|
+
def self.included(base)
|
|
5
|
+
base.extend(ClassMethods)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def add_to_index(index, key, value, unique = false)
|
|
9
|
+
if self.is_a? Neography::Node
|
|
10
|
+
self.neo_server.add_node_to_index(index, key, value, self.neo_id, unique)
|
|
11
|
+
else
|
|
12
|
+
self.neo_server.add_relationship_to_index(index, key, value, self.neo_id)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def remove_from_index(*args)
|
|
17
|
+
if self.is_a? Neography::Node
|
|
18
|
+
self.neo_server.remove_node_from_index(*args)
|
|
19
|
+
else
|
|
20
|
+
self.neo_server.remove_relationship_from_index(*args)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
module ClassMethods
|
|
25
|
+
def find(*args)
|
|
26
|
+
db = args[3] ? args.pop : Neography::Rest.new
|
|
27
|
+
|
|
28
|
+
if self <= Neography::Node
|
|
29
|
+
nodes = []
|
|
30
|
+
results = db.find_node_index(*args)
|
|
31
|
+
return nil unless results
|
|
32
|
+
results.each do |r|
|
|
33
|
+
node = self.new(r)
|
|
34
|
+
node.neo_server = db
|
|
35
|
+
nodes << node
|
|
36
|
+
end
|
|
37
|
+
nodes.size > 1 ? nodes : nodes.first
|
|
38
|
+
else
|
|
39
|
+
rels = []
|
|
40
|
+
results = db.find_relationship_index(*args)
|
|
41
|
+
return nil unless results
|
|
42
|
+
results.each do |r|
|
|
43
|
+
rel = self.new(r, db)
|
|
44
|
+
rels << rel
|
|
45
|
+
end
|
|
46
|
+
rels.size > 1 ? rels : rels.first
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
class MultiJsonParser
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# I know this looks pretty ugly, but we have issues with Neo4j returning true, false,
|
|
5
|
+
# plain numbers and plain strings, which is considered by some JSON libraries to be
|
|
6
|
+
# invalid JSON, but some consider it perfectly fine.
|
|
7
|
+
# This ugly hack deals with the problem. Send me a Pull Request if you
|
|
8
|
+
# come up with a nicer solution... please!
|
|
9
|
+
#
|
|
10
|
+
def self.json(body)
|
|
11
|
+
begin
|
|
12
|
+
MultiJson.load(body)
|
|
13
|
+
rescue MultiJson::DecodeError, ArgumentError
|
|
14
|
+
case
|
|
15
|
+
when body == "true"
|
|
16
|
+
true
|
|
17
|
+
when body == "false"
|
|
18
|
+
false
|
|
19
|
+
when body.match(/\A[+-]?\d+?(\.\d+)?\Z/) == nil ? false : true
|
|
20
|
+
Float(body)
|
|
21
|
+
else
|
|
22
|
+
body[1..-2]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
module Neography
|
|
2
|
+
class Node < PropertyContainer
|
|
3
|
+
include Neography::Index
|
|
4
|
+
include Neography::NodeRelationship
|
|
5
|
+
include Neography::NodePath
|
|
6
|
+
include Neography::Equal
|
|
7
|
+
include Neography::Property
|
|
8
|
+
|
|
9
|
+
attr_accessor :neo_server
|
|
10
|
+
|
|
11
|
+
def self.create(props = nil, db = Neography::Rest.new)
|
|
12
|
+
raise ArgumentError.new("syntax deprecated") if props.is_a?(Neography::Rest)
|
|
13
|
+
|
|
14
|
+
node = self.new(db.create_node(props))
|
|
15
|
+
node.neo_server = db
|
|
16
|
+
node
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.create_unique(index, key, value, props = nil, db = Neography::Rest.new)
|
|
20
|
+
raise ArgumentError.new("syntax deprecated") if props.is_a?(Neography::Rest)
|
|
21
|
+
|
|
22
|
+
node = self.new(db.create_unique_node(index, key, value, props))
|
|
23
|
+
node.neo_server = db
|
|
24
|
+
node
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.load(node, db = Neography::Rest.new)
|
|
28
|
+
raise ArgumentError.new("syntax deprecated") if node.is_a?(Neography::Rest)
|
|
29
|
+
node = node.first if node.kind_of?(Array)
|
|
30
|
+
node = db.get_node(node) if (node.to_s.match(/^\d+$/) or node.to_s.split("/").last.match(/^\d+$/))
|
|
31
|
+
if node
|
|
32
|
+
node = self.new(node)
|
|
33
|
+
node.neo_server = db
|
|
34
|
+
end
|
|
35
|
+
node
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def find(*args)
|
|
39
|
+
node = self.new
|
|
40
|
+
node.find(args)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def del
|
|
44
|
+
neo_server.delete_node!(self.neo_id)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def exist?
|
|
48
|
+
begin
|
|
49
|
+
neo_server.get_node(self.neo_id)
|
|
50
|
+
true
|
|
51
|
+
rescue NodeNotFoundException
|
|
52
|
+
false
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
##
|
|
57
|
+
# List of labels of current node.
|
|
58
|
+
# Returns array of strings
|
|
59
|
+
def labels
|
|
60
|
+
self.neo_server.get_node_labels(self.neo_id)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Neography
|
|
2
|
+
module NodePath
|
|
3
|
+
|
|
4
|
+
def all_paths_to(to)
|
|
5
|
+
PathTraverser.new(self, to, "allPaths", true)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def all_simple_paths_to(to)
|
|
9
|
+
PathTraverser.new(self, to, "allSimplePaths", true)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def all_shortest_paths_to(to)
|
|
13
|
+
PathTraverser.new(self, to, "shortestPath", true)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def path_to(to)
|
|
17
|
+
PathTraverser.new(self, to, "allPaths", false)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def simple_path_to(to)
|
|
21
|
+
PathTraverser.new(self, to, "allSimplePaths", false)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def shortest_path_to(to)
|
|
25
|
+
PathTraverser.new(self, to, "shortestPath", false)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module Neography
|
|
2
|
+
module NodeRelationship
|
|
3
|
+
|
|
4
|
+
DIRECTIONS = ["incoming", "in", "outgoing", "out", "all", "both"]
|
|
5
|
+
|
|
6
|
+
def outgoing(types=nil)
|
|
7
|
+
NodeTraverser.new(self).outgoing(types)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def incoming(types=nil)
|
|
11
|
+
NodeTraverser.new(self).incoming(types)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def both(types=nil)
|
|
15
|
+
NodeTraverser.new(self).both(types)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def rels(*types)
|
|
19
|
+
Neography::RelationshipTraverser.new(self, types, :both)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def rel(dir, type)
|
|
23
|
+
rel = Neography::RelationshipTraverser.new(self, type, dir)
|
|
24
|
+
rel = rel.first unless rel.empty?
|
|
25
|
+
rel
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def rel?(dir=nil, type=nil)
|
|
29
|
+
if DIRECTIONS.include?(dir.to_s)
|
|
30
|
+
!self.neo_server.get_node_relationships(self, dir, type).empty?
|
|
31
|
+
else
|
|
32
|
+
!self.neo_server.get_node_relationships(self, type, dir).empty?
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
module Neography
|
|
2
|
+
class NodeTraverser
|
|
3
|
+
include Enumerable
|
|
4
|
+
|
|
5
|
+
attr_accessor :order, :uniqueness, :depth, :prune, :filter, :relationships
|
|
6
|
+
|
|
7
|
+
def initialize(from, types = nil, dir = "all" )
|
|
8
|
+
@from = from
|
|
9
|
+
@order = "depth first"
|
|
10
|
+
@uniqueness = "none"
|
|
11
|
+
@relationships = Array.new
|
|
12
|
+
types.each do |type|
|
|
13
|
+
@relationships << {"type" => type.to_s, "direction" => dir.to_s }
|
|
14
|
+
end unless types.nil?
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def <<(other_node)
|
|
18
|
+
create(other_node)
|
|
19
|
+
self
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def create(other_node)
|
|
23
|
+
case @relationships.first["direction"]
|
|
24
|
+
when "outgoing", "out"
|
|
25
|
+
rel = Neography::Relationship.new(@from.neo_server.create_relationship(@relationships.first["type"], @from, other_node))
|
|
26
|
+
when "incoming", "in"
|
|
27
|
+
rel = Neography::Relationship.new(@from.neo_server.create_relationship(@relationships.first["type"], other_node, @from))
|
|
28
|
+
else
|
|
29
|
+
rel = Array.new
|
|
30
|
+
rel << Neography::Relationship.new(@from.neo_server.create_relationship(@relationships.first["type"], @from, other_node))
|
|
31
|
+
rel << Neography::Relationship.new(@from.neo_server.create_relationship(@relationships.first["type"], other_node, @from))
|
|
32
|
+
end
|
|
33
|
+
rel
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def both(type)
|
|
37
|
+
@relationships << {"type" => type.to_s, "direction" => "all"}
|
|
38
|
+
self
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def outgoing(type)
|
|
42
|
+
@relationships << {"type" => type.to_s, "direction" => "out"}
|
|
43
|
+
self
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def incoming(type)
|
|
47
|
+
@relationships << {"type" => type.to_s, "direction" => "in"}
|
|
48
|
+
self
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def uniqueness(u)
|
|
52
|
+
@uniqueness = u
|
|
53
|
+
self
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def order(o)
|
|
57
|
+
@order = o
|
|
58
|
+
self
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def filter(body)
|
|
62
|
+
@filter = {
|
|
63
|
+
"language" => "javascript",
|
|
64
|
+
"body" => body
|
|
65
|
+
}
|
|
66
|
+
self
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def prune(body)
|
|
70
|
+
@prune = {
|
|
71
|
+
"language" => "javascript",
|
|
72
|
+
"body" => body
|
|
73
|
+
}
|
|
74
|
+
self
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def depth(d)
|
|
78
|
+
d = 2147483647 if d == :all
|
|
79
|
+
@depth = d
|
|
80
|
+
self
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def include_start_node
|
|
84
|
+
@filter = {
|
|
85
|
+
"language" => "builtin",
|
|
86
|
+
"name" => "all"
|
|
87
|
+
}
|
|
88
|
+
self
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def size
|
|
92
|
+
[*self].size
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
alias_method :length, :size
|
|
96
|
+
|
|
97
|
+
def [](index)
|
|
98
|
+
each_with_index {|node,i| break node if index == i}
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def empty?
|
|
102
|
+
first == nil
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def each
|
|
106
|
+
iterator.each do |i|
|
|
107
|
+
node = @from.class.new(i)
|
|
108
|
+
node.neo_server = @from.neo_server
|
|
109
|
+
yield node
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def iterator
|
|
114
|
+
options = {
|
|
115
|
+
"order" => @order,
|
|
116
|
+
"uniqueness" => @uniqueness,
|
|
117
|
+
"relationships" => @relationships
|
|
118
|
+
}
|
|
119
|
+
options["prune evaluator"] = @prune unless @prune.nil?
|
|
120
|
+
options["return filter"] = @filter unless @filter.nil?
|
|
121
|
+
options["depth"] = @depth unless @depth.nil?
|
|
122
|
+
|
|
123
|
+
if @relationships[0]["type"].empty?
|
|
124
|
+
rels = @from.neo_server.get_node_relationships(@from, @relationships[0]["direction"]) || []
|
|
125
|
+
case @relationships[0]["direction"]
|
|
126
|
+
when "in"
|
|
127
|
+
rels.collect { |r| @from.neo_server.get_node(r["start"]) } #.uniq
|
|
128
|
+
when "out"
|
|
129
|
+
rels.collect { |r| @from.neo_server.get_node(r["end"]) } #.uniq
|
|
130
|
+
else
|
|
131
|
+
rels.collect { |r|
|
|
132
|
+
if @from.neo_id == r["start"].split('/').last
|
|
133
|
+
@from.neo_server.get_node(r["end"])
|
|
134
|
+
else
|
|
135
|
+
@from.neo_server.get_node(r["start"])
|
|
136
|
+
end
|
|
137
|
+
} #.uniq
|
|
138
|
+
end
|
|
139
|
+
else
|
|
140
|
+
@from.neo_server.traverse(@from, "nodes", options)
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
end
|