neo4j 2.0.0.alpha.5-java → 2.0.0.alpha.6-java
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.
- data/CHANGELOG +12 -0
- data/Gemfile +0 -4
- data/README.rdoc +106 -62
- data/lib/neo4j.rb +7 -33
- data/lib/neo4j/performance.rb +43 -0
- data/lib/neo4j/rails/accept_id.rb +19 -18
- data/lib/neo4j/rails/attributes.rb +366 -120
- data/lib/neo4j/rails/finders.rb +41 -15
- data/lib/neo4j/rails/has_n.rb +203 -0
- data/lib/neo4j/rails/identity.rb +25 -0
- data/lib/neo4j/rails/model.rb +65 -242
- data/lib/neo4j/rails/nested_attributes.rb +108 -0
- data/lib/neo4j/rails/node_persistance.rb +56 -0
- data/lib/neo4j/rails/observer.rb +0 -2
- data/lib/neo4j/rails/persistence.rb +32 -154
- data/lib/neo4j/rails/rack_middleware.rb +26 -2
- data/lib/neo4j/rails/rails.rb +9 -6
- data/lib/neo4j/rails/railtie.rb +1 -2
- data/lib/neo4j/rails/relationship.rb +18 -125
- data/lib/neo4j/rails/relationship_persistence.rb +107 -0
- data/lib/neo4j/rails/relationships/node_dsl.rb +72 -44
- data/lib/neo4j/rails/relationships/relationships.rb +187 -59
- data/lib/neo4j/rails/relationships/rels_dsl.rb +18 -17
- data/lib/neo4j/rails/relationships/storage.rb +19 -17
- data/lib/neo4j/rails/timestamps.rb +53 -51
- data/lib/neo4j/rails/transaction.rb +9 -1
- data/lib/neo4j/rails/validations/uniqueness.rb +1 -1
- data/lib/neo4j/rails/versioning/versioning.rb +2 -2
- data/lib/neo4j/version.rb +1 -1
- data/lib/orm_adapter/adapters/neo4j.rb +47 -46
- data/neo4j.gemspec +1 -1
- metadata +10 -69
- data/lib/neo4j/algo/algo.rb +0 -294
- data/lib/neo4j/batch/batch.rb +0 -4
- data/lib/neo4j/batch/indexer.rb +0 -109
- data/lib/neo4j/batch/inserter.rb +0 -179
- data/lib/neo4j/batch/rule_inserter.rb +0 -24
- data/lib/neo4j/batch/rule_node.rb +0 -72
- data/lib/neo4j/config.rb +0 -177
- data/lib/neo4j/core_ext/class/inheritable_attributes.rb +0 -12
- data/lib/neo4j/core_ext/class/rewrite_inheritable_attributes.rb +0 -170
- data/lib/neo4j/database.rb +0 -158
- data/lib/neo4j/equal.rb +0 -21
- data/lib/neo4j/event_handler.rb +0 -263
- data/lib/neo4j/has_list/class_methods.rb +0 -11
- data/lib/neo4j/has_list/has_list.rb +0 -3
- data/lib/neo4j/has_list/mapping.rb +0 -133
- data/lib/neo4j/has_n/class_methods.rb +0 -119
- data/lib/neo4j/has_n/decl_relationship_dsl.rb +0 -246
- data/lib/neo4j/has_n/has_n.rb +0 -3
- data/lib/neo4j/has_n/mapping.rb +0 -98
- data/lib/neo4j/identity_map.rb +0 -140
- data/lib/neo4j/index/class_methods.rb +0 -108
- data/lib/neo4j/index/index.rb +0 -39
- data/lib/neo4j/index/indexer.rb +0 -341
- data/lib/neo4j/index/indexer_registry.rb +0 -68
- data/lib/neo4j/index/lucene_query.rb +0 -256
- data/lib/neo4j/load.rb +0 -25
- data/lib/neo4j/migrations/class_methods.rb +0 -110
- data/lib/neo4j/migrations/extensions.rb +0 -58
- data/lib/neo4j/migrations/lazy_node_mixin.rb +0 -41
- data/lib/neo4j/migrations/migration.rb +0 -112
- data/lib/neo4j/migrations/migrations.rb +0 -6
- data/lib/neo4j/migrations/node_mixin.rb +0 -80
- data/lib/neo4j/migrations/ref_node_wrapper.rb +0 -32
- data/lib/neo4j/model.rb +0 -4
- data/lib/neo4j/neo4j.rb +0 -216
- data/lib/neo4j/node.rb +0 -270
- data/lib/neo4j/node_mixin/class_methods.rb +0 -51
- data/lib/neo4j/node_mixin/node_mixin.rb +0 -141
- data/lib/neo4j/paginated.rb +0 -23
- data/lib/neo4j/property/class_methods.rb +0 -79
- data/lib/neo4j/property/property.rb +0 -111
- data/lib/neo4j/rails/mapping/property.rb +0 -183
- data/lib/neo4j/rails/rel_persistence.rb +0 -237
- data/lib/neo4j/relationship.rb +0 -239
- data/lib/neo4j/relationship_mixin/class_methods.rb +0 -36
- data/lib/neo4j/relationship_mixin/relationship_mixin.rb +0 -142
- data/lib/neo4j/relationship_set.rb +0 -58
- data/lib/neo4j/rels/rels.rb +0 -110
- data/lib/neo4j/rels/traverser.rb +0 -102
- data/lib/neo4j/rule/class_methods.rb +0 -201
- data/lib/neo4j/rule/event_listener.rb +0 -66
- data/lib/neo4j/rule/functions/count.rb +0 -43
- data/lib/neo4j/rule/functions/function.rb +0 -74
- data/lib/neo4j/rule/functions/functions.rb +0 -3
- data/lib/neo4j/rule/functions/sum.rb +0 -29
- data/lib/neo4j/rule/rule.rb +0 -150
- data/lib/neo4j/rule/rule_node.rb +0 -217
- data/lib/neo4j/to_java.rb +0 -31
- data/lib/neo4j/transaction.rb +0 -73
- data/lib/neo4j/traversal/filter_predicate.rb +0 -25
- data/lib/neo4j/traversal/prune_evaluator.rb +0 -14
- data/lib/neo4j/traversal/rel_expander.rb +0 -31
- data/lib/neo4j/traversal/traversal.rb +0 -141
- data/lib/neo4j/traversal/traverser.rb +0 -284
- data/lib/neo4j/type_converters/type_converters.rb +0 -288
@@ -1,133 +0,0 @@
|
|
1
|
-
module Neo4j
|
2
|
-
module HasList
|
3
|
-
|
4
|
-
# Enables creating and traversal of nodes in a list.
|
5
|
-
#
|
6
|
-
# It uses the TimeLine http://api.neo4j.org/current/org/neo4j/index/timeline/Timeline.html,
|
7
|
-
#
|
8
|
-
# Includes the Enumerable Mixin.
|
9
|
-
# The Neo4j::Mapping::ClassMethods::List#has_list methods returns an object of this type.
|
10
|
-
#
|
11
|
-
# === Example, index same as size of list
|
12
|
-
#
|
13
|
-
# class Person
|
14
|
-
# include Neo4j::NodeMixin
|
15
|
-
# has_list :feeds
|
16
|
-
# end
|
17
|
-
#
|
18
|
-
# person = Person.new
|
19
|
-
# person.feeds << Neo4j::Node:new << Neo4j::Node.new
|
20
|
-
#
|
21
|
-
# === Example, using a custom index
|
22
|
-
#
|
23
|
-
# class Person
|
24
|
-
# include Neo4j::NodeMixin
|
25
|
-
# has_list :feeds
|
26
|
-
# end
|
27
|
-
#
|
28
|
-
# person = Person.new
|
29
|
-
# person.feeds[42] = (a = Neo4j::Node:new)
|
30
|
-
# person.feeds[1251] = Neo4j::Node.new
|
31
|
-
#
|
32
|
-
# person.feeds[42] # => a
|
33
|
-
#
|
34
|
-
class Mapping
|
35
|
-
include Enumerable
|
36
|
-
include ToJava
|
37
|
-
|
38
|
-
|
39
|
-
def initialize(indexer_for, node, name)
|
40
|
-
@index = Neo4j.started_db.lucene.for_nodes("#{indexer_for.to_s.gsub('::', '_')}_#{name}-timeline", Neo4j::Config[:lucene][:exact])
|
41
|
-
@time_line = org.neo4j.index.lucene.LuceneTimeline.new(Neo4j.started_db.graph, @index)
|
42
|
-
@node = node
|
43
|
-
@name = name
|
44
|
-
self.size = 0 unless size
|
45
|
-
end
|
46
|
-
|
47
|
-
# returns the size of this list
|
48
|
-
# notice in order to get correct result you must call the #remove method when an item is removed from the list
|
49
|
-
def size
|
50
|
-
@node["_list_size_#{@name}"]
|
51
|
-
end
|
52
|
-
|
53
|
-
# same as #size == 0
|
54
|
-
def empty?
|
55
|
-
size == 0
|
56
|
-
end
|
57
|
-
|
58
|
-
# returns the first node with index n
|
59
|
-
def [](n)
|
60
|
-
@time_line.getBetween(n, n).first
|
61
|
-
end
|
62
|
-
|
63
|
-
# returns all nodes with the given index n
|
64
|
-
def all(n)
|
65
|
-
@time_line.getBetween(n, n)
|
66
|
-
end
|
67
|
-
|
68
|
-
# returns the first node in the list or nil
|
69
|
-
def first
|
70
|
-
@time_line.getFirst()
|
71
|
-
end
|
72
|
-
|
73
|
-
# returns the last node in the list or nil
|
74
|
-
def last
|
75
|
-
@time_line.getLast
|
76
|
-
end
|
77
|
-
|
78
|
-
# adds a node to the list with the given index n
|
79
|
-
def []=(n, other_node)
|
80
|
-
@time_line.add(other_node, n)
|
81
|
-
self.size = self.size + 1
|
82
|
-
end
|
83
|
-
|
84
|
-
# returns all the nodes between the given Range
|
85
|
-
def between(range)
|
86
|
-
@time_line.getBetween(range.first, range.end)
|
87
|
-
end
|
88
|
-
|
89
|
-
# removes one node from the list and decrases the size of the list,
|
90
|
-
def remove(node)
|
91
|
-
@index.remove(node, "timestamp")
|
92
|
-
self.size = self.size - 1
|
93
|
-
end
|
94
|
-
|
95
|
-
# Required by the Enumerable mixin so that we can
|
96
|
-
#
|
97
|
-
# ==== Example
|
98
|
-
#
|
99
|
-
# class Person
|
100
|
-
# include Neo4j::NodeMixin
|
101
|
-
# has_list :feeds
|
102
|
-
# end
|
103
|
-
#
|
104
|
-
# person.feeds.each {|node| node}
|
105
|
-
#
|
106
|
-
def each
|
107
|
-
@time_line.getBetween(java.lang.Long::MIN_VALUE,java.lang.Long::MAX_VALUE).iterator.each do |node|
|
108
|
-
if @raw then
|
109
|
-
yield node
|
110
|
-
else
|
111
|
-
yield node.wrapper
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
# If called then it will only return the raw java nodes and not the Ruby wrappers using the Neo4j::NodeMixin
|
117
|
-
def raw
|
118
|
-
@raw = true
|
119
|
-
end
|
120
|
-
|
121
|
-
def <<(other)
|
122
|
-
@time_line.add(other._java_node, size)
|
123
|
-
self.size = self.size + 1
|
124
|
-
self
|
125
|
-
end
|
126
|
-
|
127
|
-
private
|
128
|
-
def size=(size)
|
129
|
-
@node["_list_size_#{@name}"] = size
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
@@ -1,119 +0,0 @@
|
|
1
|
-
module Neo4j
|
2
|
-
module HasN
|
3
|
-
module ClassMethods
|
4
|
-
include Neo4j::ToJava
|
5
|
-
|
6
|
-
# Specifies a relationship between two node classes.
|
7
|
-
# Generates assignment and accessor methods for the given relationship.
|
8
|
-
# Both incoming and outgoing relationships can be declared, see Neo4j::HasN::DeclRelationshipDsl
|
9
|
-
#
|
10
|
-
# ==== Example
|
11
|
-
#
|
12
|
-
# class FolderNode
|
13
|
-
# include Ne4j::NodeMixin
|
14
|
-
# has_n(:files)
|
15
|
-
# end
|
16
|
-
#
|
17
|
-
# folder = FolderNode.new
|
18
|
-
# folder.files << Neo4j::Node.new << Neo4j::Node.new
|
19
|
-
# folder.files.inject {...}
|
20
|
-
#
|
21
|
-
# FolderNode.files #=> 'files' the name of the relationship
|
22
|
-
#
|
23
|
-
# ==== Example has_n(x).to(...)
|
24
|
-
#
|
25
|
-
# You can declare which class it has relationship to.
|
26
|
-
# The generated relationships will be prefixed with the name of that class.
|
27
|
-
#
|
28
|
-
# class FolderNode
|
29
|
-
# include Ne4j::NodeMixin
|
30
|
-
# has_n(:files).to(File)
|
31
|
-
# end
|
32
|
-
#
|
33
|
-
# FolderNode.files #=> 'File#files' the name of the relationship
|
34
|
-
#
|
35
|
-
# ==== Example has_n(x).from(class, has_n_name)
|
36
|
-
#
|
37
|
-
# Neo4j.rb can also generate accessor method for traversing and adding relationship on incoming nodes.
|
38
|
-
#
|
39
|
-
# class FileNode
|
40
|
-
# include Ne4j::NodeMixin
|
41
|
-
# has_one(:folder).from(FolderNode, :files)
|
42
|
-
# end
|
43
|
-
#
|
44
|
-
#
|
45
|
-
# ==== Returns
|
46
|
-
#
|
47
|
-
# * This method returns Neo4j::HasN::DeclRelationshipDsl
|
48
|
-
# * The generated has_n method returns a Neo4j::HasN::Mapping object
|
49
|
-
#
|
50
|
-
def has_n(rel_type)
|
51
|
-
clazz = self
|
52
|
-
module_eval(%Q{
|
53
|
-
def #{rel_type}
|
54
|
-
dsl = _decl_rels_for('#{rel_type}'.to_sym)
|
55
|
-
Neo4j::HasN::Mapping.new(self, dsl)
|
56
|
-
end}, __FILE__, __LINE__)
|
57
|
-
|
58
|
-
|
59
|
-
module_eval(%Q{
|
60
|
-
def #{rel_type}_rels
|
61
|
-
dsl = _decl_rels_for('#{rel_type}'.to_sym)
|
62
|
-
dsl.all_relationships(self)
|
63
|
-
end}, __FILE__, __LINE__)
|
64
|
-
|
65
|
-
instance_eval(%Q{
|
66
|
-
def #{rel_type}
|
67
|
-
_decl_rels[:#{rel_type}].rel_type.to_s
|
68
|
-
end}, __FILE__, __LINE__)
|
69
|
-
|
70
|
-
_decl_rels[rel_type.to_sym] = DeclRelationshipDsl.new(rel_type, false, clazz)
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
# Specifies a relationship between two node classes.
|
75
|
-
# Generates assignment and accessor methods for the given relationship
|
76
|
-
# Old relationship is deleted when a new relationship is assigned.
|
77
|
-
# Both incoming and outgoing relationships can be declared, see Neo4j::HasN::DeclRelationshipDsl
|
78
|
-
#
|
79
|
-
# ==== Example
|
80
|
-
#
|
81
|
-
# class FileNode
|
82
|
-
# include Ne4j::NodeMixin
|
83
|
-
# has_one(:folder)
|
84
|
-
# end
|
85
|
-
#
|
86
|
-
# file = FileNode.new
|
87
|
-
# file.folder = Neo4j::Node.new
|
88
|
-
# file.folder # => the node above
|
89
|
-
# file.folder_rel # => the relationship object between those nodes
|
90
|
-
#
|
91
|
-
# ==== Returns
|
92
|
-
#
|
93
|
-
# Neo4j::HasN::DeclRelationshipDsl
|
94
|
-
#
|
95
|
-
def has_one(rel_type)
|
96
|
-
clazz = self
|
97
|
-
module_eval(%Q{def #{rel_type}=(value)
|
98
|
-
dsl = _decl_rels_for(:#{rel_type})
|
99
|
-
rel = dsl.single_relationship(self)
|
100
|
-
rel.del unless rel.nil?
|
101
|
-
dsl.create_relationship_to(self, value) if value
|
102
|
-
end}, __FILE__, __LINE__)
|
103
|
-
|
104
|
-
module_eval(%Q{def #{rel_type}
|
105
|
-
dsl = _decl_rels_for(:#{rel_type})
|
106
|
-
dsl.single_node(self)
|
107
|
-
end}, __FILE__, __LINE__)
|
108
|
-
|
109
|
-
module_eval(%Q{def #{rel_type}_rel
|
110
|
-
dsl = _decl_rels_for(:#{rel_type})
|
111
|
-
dsl.single_relationship(self)
|
112
|
-
end}, __FILE__, __LINE__)
|
113
|
-
|
114
|
-
_decl_rels[rel_type.to_sym] = DeclRelationshipDsl.new(rel_type, true, clazz)
|
115
|
-
end
|
116
|
-
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
@@ -1,246 +0,0 @@
|
|
1
|
-
module Neo4j
|
2
|
-
module HasN
|
3
|
-
|
4
|
-
|
5
|
-
# A DSL for declared relationships has_n and has_one
|
6
|
-
# This DSL will be used to create accessor methods for relationships.
|
7
|
-
# Instead of using the 'raw' Neo4j::NodeMixin#rels method where one needs to know
|
8
|
-
# the name of relationship and direction one can use the generated accessor methods.
|
9
|
-
#
|
10
|
-
# The DSL can also be used to specify a mapping to a Ruby class for a relationship, see Neo4j::HasN::DeclRelationshipDsl#relationship
|
11
|
-
#
|
12
|
-
# ==== Example
|
13
|
-
#
|
14
|
-
# class Folder
|
15
|
-
# include Neo4j::NodeMixin
|
16
|
-
# property :name
|
17
|
-
# # Declaring a Many relationship to any other node
|
18
|
-
# has_n(:files)
|
19
|
-
# end
|
20
|
-
#
|
21
|
-
# class File
|
22
|
-
# include Neo4j::NodeMixin
|
23
|
-
# # declaring a incoming relationship from Folder's relationship files
|
24
|
-
# has_one(:folder).from(Folder, :files)
|
25
|
-
# end
|
26
|
-
#
|
27
|
-
# The following methods will be generated:
|
28
|
-
# <b>Folder#files</b> :: returns an Enumerable of outgoing nodes for relationship 'files'
|
29
|
-
# <b>Folder#files_rels</b> :: returns an Enumerable of outgoing relationships for relationship 'files'
|
30
|
-
# <b>File#folder</b> :: for adding one node for the relationship 'files' from the outgoing Folder node
|
31
|
-
# <b>File#folder_rel</b> :: for accessing relationship 'files' from the outgoing Folder node
|
32
|
-
# <b>File#folder</b> :: for accessing nodes from relationship 'files' from the outgoing Folder node
|
33
|
-
#
|
34
|
-
class DeclRelationshipDsl
|
35
|
-
include Neo4j::ToJava
|
36
|
-
|
37
|
-
attr_reader :target_class, :source_class, :dir, :rel_type
|
38
|
-
|
39
|
-
def initialize(method_id, has_one, target_class)
|
40
|
-
@dir = :outgoing
|
41
|
-
@method_id = method_id
|
42
|
-
@has_one = has_one
|
43
|
-
@rel_type = method_id
|
44
|
-
@target_class = target_class
|
45
|
-
@source_class = target_class
|
46
|
-
end
|
47
|
-
|
48
|
-
def to_s
|
49
|
-
"DeclRelationshipDsl #{object_id} dir: #{@dir} rel_id: #{@method_id}, rel_type: #{@rel_type}, target_class:#{@target_class} rel_class:#{@relationship}"
|
50
|
-
end
|
51
|
-
|
52
|
-
def has_one?
|
53
|
-
@has_one
|
54
|
-
end
|
55
|
-
|
56
|
-
def has_n?
|
57
|
-
!@has_one
|
58
|
-
end
|
59
|
-
|
60
|
-
def java_rel_type
|
61
|
-
type_to_java(@rel_type)
|
62
|
-
end
|
63
|
-
|
64
|
-
def java_dir
|
65
|
-
dir_to_java(@dir)
|
66
|
-
end
|
67
|
-
|
68
|
-
def each_node(node, &block) #:nodoc:
|
69
|
-
node._java_node.getRelationships(java_rel_type, java_dir).each do |rel|
|
70
|
-
block.call(rel.getOtherNode(node).wrapper)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def _each_node(node, &block) #:nodoc:
|
75
|
-
node._java_node.getRelationships(java_rel_type, java_dir).each do |rel|
|
76
|
-
block.call rel.getOtherNode(node)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def incoming? #:nodoc:
|
81
|
-
@dir == :incoming
|
82
|
-
end
|
83
|
-
|
84
|
-
def single_node(node) #:nodoc:
|
85
|
-
rel = single_relationship(node)
|
86
|
-
rel && rel.other_node(node).wrapper
|
87
|
-
end
|
88
|
-
|
89
|
-
def single_relationship(node) #:nodoc:
|
90
|
-
node._java_node.rel(dir, rel_type)
|
91
|
-
end
|
92
|
-
|
93
|
-
def _all_relationships(node) #:nodoc:
|
94
|
-
node._java_node.getRelationships(java_rel_type, java_dir)
|
95
|
-
end
|
96
|
-
|
97
|
-
def all_relationships(node) #:nodoc:
|
98
|
-
Neo4j::Rels::Traverser.new(node._java_node, [rel_type], dir)
|
99
|
-
end
|
100
|
-
|
101
|
-
def create_relationship_to(node, other) # :nodoc:
|
102
|
-
from, to = incoming? ? [other, node] : [node, other]
|
103
|
-
|
104
|
-
if relationship_class
|
105
|
-
relationship_class.new(@rel_type, from._java_node, to._java_node)
|
106
|
-
else
|
107
|
-
from._java_node.create_relationship_to(to._java_node, java_rel_type)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
# Specifies an outgoing relationship.
|
112
|
-
# The name of the outgoing class will be used as a prefix for the relationship used.
|
113
|
-
#
|
114
|
-
# ==== Arguments
|
115
|
-
# clazz:: to which class this relationship goes
|
116
|
-
# relationship:: optional, the relationship to use
|
117
|
-
#
|
118
|
-
# ==== Example
|
119
|
-
# class FolderNode
|
120
|
-
# include Neo4j::NodeMixin
|
121
|
-
# has_n(:files).to(FileNode)
|
122
|
-
# end
|
123
|
-
#
|
124
|
-
# folder = FolderNode.new
|
125
|
-
# # generate a relationship between folder and file of type 'FileNode#files'
|
126
|
-
# folder.files << FileNode.new
|
127
|
-
#
|
128
|
-
# ==== Example, without prefix
|
129
|
-
#
|
130
|
-
# class FolderNode
|
131
|
-
# include Neo4j::NodeMixin
|
132
|
-
# has_n(:files).to(:contains)
|
133
|
-
# end
|
134
|
-
#
|
135
|
-
# file = FileNode.new
|
136
|
-
# # create an outgoing relationship of type 'contains' from folder node to file
|
137
|
-
# folder.files << FolderNode.new
|
138
|
-
#
|
139
|
-
def to(target)
|
140
|
-
@dir = :outgoing
|
141
|
-
|
142
|
-
if (Class === target)
|
143
|
-
# handle e.g. has_n(:friends).to(class)
|
144
|
-
@target_class = target
|
145
|
-
@rel_type = "#{@source_class}##{@method_id}"
|
146
|
-
elsif (Symbol === target)
|
147
|
-
# handle e.g. has_n(:friends).to(:knows)
|
148
|
-
@rel_type = target.to_s
|
149
|
-
else
|
150
|
-
raise "Expected a class or a symbol for, got #{target}/#{target.class}"
|
151
|
-
end
|
152
|
-
self
|
153
|
-
end
|
154
|
-
|
155
|
-
# Specifies an incoming relationship.
|
156
|
-
# Will use the outgoing relationship given by the from class.
|
157
|
-
#
|
158
|
-
# ==== Example, with prefix FileNode
|
159
|
-
# class FolderNode
|
160
|
-
# include Neo4j::NodeMixin
|
161
|
-
# has_n(:files).to(FileNode)
|
162
|
-
# end
|
163
|
-
#
|
164
|
-
# class FileNode
|
165
|
-
# include Neo4j::NodeMixin
|
166
|
-
# # will only traverse any incoming relationship of type files from node FileNode
|
167
|
-
# has_one(:folder).from(FolderNode, :files)
|
168
|
-
# end
|
169
|
-
#
|
170
|
-
# file = FileNode.new
|
171
|
-
# # create an outgoing relationship of type 'FileNode#files' from folder node to file (FileNode is the prefix).
|
172
|
-
# file.folder = FolderNode.new
|
173
|
-
#
|
174
|
-
# ==== Example, without prefix
|
175
|
-
#
|
176
|
-
# class FolderNode
|
177
|
-
# include Neo4j::NodeMixin
|
178
|
-
# has_n(:files)
|
179
|
-
# end
|
180
|
-
#
|
181
|
-
# class FileNode
|
182
|
-
# include Neo4j::NodeMixin
|
183
|
-
# has_one(:folder).from(:files) # will traverse any incoming relationship of type files
|
184
|
-
# end
|
185
|
-
#
|
186
|
-
# file = FileNode.new
|
187
|
-
# # create an outgoing relationship of type 'files' from folder node to file
|
188
|
-
# file.folder = FolderNode.new
|
189
|
-
#
|
190
|
-
#
|
191
|
-
def from(*args)
|
192
|
-
@dir = :incoming
|
193
|
-
|
194
|
-
if (args.size > 1)
|
195
|
-
# handle specified (prefixed) relationship, e.g. has_n(:known_by).from(clazz, :type)
|
196
|
-
@target_class = args[0]
|
197
|
-
@rel_type = "#{@target_class}##{args[1]}"
|
198
|
-
@relationship_name = args[1]
|
199
|
-
elsif (Symbol === args[0])
|
200
|
-
# handle unspecified (unprefixed) relationship, e.g. has_n(:known_by).from(:type)
|
201
|
-
@rel_type = args[0]
|
202
|
-
else
|
203
|
-
raise "Expected a symbol for, got #{args[0]}"
|
204
|
-
end
|
205
|
-
self
|
206
|
-
end
|
207
|
-
|
208
|
-
# Specifies which relationship ruby class to use for the relationship
|
209
|
-
#
|
210
|
-
# ==== Example
|
211
|
-
#
|
212
|
-
# class OrderLine
|
213
|
-
# include Neo4j::RelationshipMixin
|
214
|
-
# property :units
|
215
|
-
# property :unit_price
|
216
|
-
# end
|
217
|
-
#
|
218
|
-
# class Order
|
219
|
-
# property :total_cost
|
220
|
-
# property :dispatched
|
221
|
-
# has_n(:products).to(Product).relationship(OrderLine)
|
222
|
-
# end
|
223
|
-
#
|
224
|
-
# order = Order.new
|
225
|
-
# order.products << Product.new
|
226
|
-
# order.products_rels.first # => OrderLine
|
227
|
-
#
|
228
|
-
def relationship(rel_class)
|
229
|
-
@relationship = rel_class
|
230
|
-
self
|
231
|
-
end
|
232
|
-
|
233
|
-
def relationship_class # :nodoc:
|
234
|
-
if !@relationship_name.nil? && @relationship.nil?
|
235
|
-
other_class_dsl = @target_class._decl_rels[@relationship_name]
|
236
|
-
if other_class_dsl
|
237
|
-
@relationship = other_class_dsl.relationship_class
|
238
|
-
else
|
239
|
-
Neo4j.logger.warn "Unknown outgoing relationship #{@relationship_name} on #{@target_class}"
|
240
|
-
end
|
241
|
-
end
|
242
|
-
@relationship
|
243
|
-
end
|
244
|
-
end
|
245
|
-
end
|
246
|
-
end
|