neo4j 1.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. data/CHANGELOG +141 -0
  2. data/CONTRIBUTORS +15 -0
  3. data/Gemfile +3 -0
  4. data/README.rdoc +2015 -0
  5. data/lib/neo4j.old/batch_inserter.rb +144 -0
  6. data/lib/neo4j.old/config.rb +138 -0
  7. data/lib/neo4j.old/event_handler.rb +73 -0
  8. data/lib/neo4j.old/extensions/activemodel.rb +158 -0
  9. data/lib/neo4j.old/extensions/aggregate.rb +12 -0
  10. data/lib/neo4j.old/extensions/aggregate/aggregate_enum.rb +40 -0
  11. data/lib/neo4j.old/extensions/aggregate/ext/node_mixin.rb +69 -0
  12. data/lib/neo4j.old/extensions/aggregate/node_aggregate.rb +8 -0
  13. data/lib/neo4j.old/extensions/aggregate/node_aggregate_mixin.rb +331 -0
  14. data/lib/neo4j.old/extensions/aggregate/node_aggregator.rb +216 -0
  15. data/lib/neo4j.old/extensions/aggregate/node_group.rb +43 -0
  16. data/lib/neo4j.old/extensions/aggregate/prop_group.rb +30 -0
  17. data/lib/neo4j.old/extensions/aggregate/property_enum.rb +24 -0
  18. data/lib/neo4j.old/extensions/aggregate/props_aggregate.rb +8 -0
  19. data/lib/neo4j.old/extensions/aggregate/props_aggregate_mixin.rb +31 -0
  20. data/lib/neo4j.old/extensions/aggregate/props_aggregator.rb +80 -0
  21. data/lib/neo4j.old/extensions/find_path.rb +117 -0
  22. data/lib/neo4j.old/extensions/graph_algo.rb +1 -0
  23. data/lib/neo4j.old/extensions/graph_algo/all_simple_paths.rb +133 -0
  24. data/lib/neo4j.old/extensions/graph_algo/neo4j-graph-algo-0.3.jar +0 -0
  25. data/lib/neo4j.old/extensions/reindexer.rb +104 -0
  26. data/lib/neo4j.old/extensions/rest.rb +21 -0
  27. data/lib/neo4j.old/extensions/rest/rest.rb +336 -0
  28. data/lib/neo4j.old/extensions/rest/rest_mixin.rb +193 -0
  29. data/lib/neo4j.old/extensions/rest/server.rb +50 -0
  30. data/lib/neo4j.old/extensions/rest/stubs.rb +141 -0
  31. data/lib/neo4j.old/extensions/rest_master.rb +34 -0
  32. data/lib/neo4j.old/extensions/rest_slave.rb +31 -0
  33. data/lib/neo4j.old/extensions/tx_tracker.rb +392 -0
  34. data/lib/neo4j.old/indexer.rb +187 -0
  35. data/lib/neo4j.old/jars.rb +6 -0
  36. data/lib/neo4j.old/jars/geronimo-jta_1.1_spec-1.1.1.jar +0 -0
  37. data/lib/neo4j.old/jars/neo4j-kernel-1.0.jar +0 -0
  38. data/lib/neo4j.old/mixins/java_list_mixin.rb +139 -0
  39. data/lib/neo4j.old/mixins/java_node_mixin.rb +205 -0
  40. data/lib/neo4j.old/mixins/java_property_mixin.rb +169 -0
  41. data/lib/neo4j.old/mixins/java_relationship_mixin.rb +60 -0
  42. data/lib/neo4j.old/mixins/migration_mixin.rb +157 -0
  43. data/lib/neo4j.old/mixins/node_mixin.rb +249 -0
  44. data/lib/neo4j.old/mixins/property_class_methods.rb +265 -0
  45. data/lib/neo4j.old/mixins/rel_class_methods.rb +167 -0
  46. data/lib/neo4j.old/mixins/relationship_mixin.rb +103 -0
  47. data/lib/neo4j.old/neo.rb +247 -0
  48. data/lib/neo4j.old/node.rb +49 -0
  49. data/lib/neo4j.old/reference_node.rb +15 -0
  50. data/lib/neo4j.old/relationship.rb +85 -0
  51. data/lib/neo4j.old/relationships/decl_relationship_dsl.rb +164 -0
  52. data/lib/neo4j.old/relationships/has_list.rb +101 -0
  53. data/lib/neo4j.old/relationships/has_n.rb +129 -0
  54. data/lib/neo4j.old/relationships/node_traverser.rb +138 -0
  55. data/lib/neo4j.old/relationships/relationship_dsl.rb +149 -0
  56. data/lib/neo4j.old/relationships/traversal_position.rb +50 -0
  57. data/lib/neo4j.old/relationships/wrappers.rb +51 -0
  58. data/lib/neo4j.old/search_result.rb +72 -0
  59. data/lib/neo4j.old/transaction.rb +254 -0
  60. data/lib/neo4j.old/version.rb +3 -0
  61. data/lib/neo4j.rb +50 -0
  62. data/lib/neo4j/config.rb +137 -0
  63. data/lib/neo4j/database.rb +43 -0
  64. data/lib/neo4j/equal.rb +22 -0
  65. data/lib/neo4j/event_handler.rb +91 -0
  66. data/lib/neo4j/index.rb +157 -0
  67. data/lib/neo4j/jars/geronimo-jta_1.1_spec-1.1.1.jar +0 -0
  68. data/lib/neo4j/jars/lucene-core-2.9.2.jar +0 -0
  69. data/lib/neo4j/jars/lucene-core-3.0.1.jar +0 -0
  70. data/lib/neo4j/jars/neo4j-index-1.1.jar +0 -0
  71. data/lib/neo4j/jars/neo4j-kernel-1.1.1.jar +0 -0
  72. data/lib/neo4j/jars/neo4j-kernel-1.1.jar +0 -0
  73. data/lib/neo4j/jars/neo4j-lucene-index-0.1-20100916.085626-67.jar +0 -0
  74. data/lib/neo4j/mapping/class_methods/index.rb +21 -0
  75. data/lib/neo4j/mapping/class_methods/property.rb +139 -0
  76. data/lib/neo4j/mapping/class_methods/relationship.rb +96 -0
  77. data/lib/neo4j/mapping/class_methods/rule.rb +135 -0
  78. data/lib/neo4j/mapping/decl_relationship_dsl.rb +151 -0
  79. data/lib/neo4j/mapping/has_n.rb +117 -0
  80. data/lib/neo4j/mapping/node_mixin.rb +70 -0
  81. data/lib/neo4j/neo4j.rb +65 -0
  82. data/lib/neo4j/node.rb +82 -0
  83. data/lib/neo4j/node_mixin.rb +4 -0
  84. data/lib/neo4j/node_relationship.rb +60 -0
  85. data/lib/neo4j/node_traverser.rb +141 -0
  86. data/lib/neo4j/property.rb +72 -0
  87. data/lib/neo4j/rails/lucene_connection_closer.rb +19 -0
  88. data/lib/neo4j/rails/model.rb +210 -0
  89. data/lib/neo4j/rails/railtie.rb +16 -0
  90. data/lib/neo4j/rails/transaction.rb +29 -0
  91. data/lib/neo4j/rails/value.rb +43 -0
  92. data/lib/neo4j/relationship.rb +88 -0
  93. data/lib/neo4j/relationship_traverser.rb +57 -0
  94. data/lib/neo4j/to_java.rb +17 -0
  95. data/lib/neo4j/transaction.rb +69 -0
  96. data/lib/neo4j/version.rb +3 -0
  97. data/neo4j.gemspec +30 -0
  98. metadata +243 -0
@@ -0,0 +1,247 @@
1
+ module Neo4j
2
+
3
+ class << self
4
+ extend Forwardable
5
+
6
+ ##
7
+ # Returns the current version of the database.
8
+ # This version has been set by running one or more migrations.
9
+ # The version is stored on the reference node, with property 'db_version'
10
+ # (Delegates to the Reference Node that includes the MigrationMixin.)
11
+ #
12
+ # === See Also
13
+ # Neo4j::MigrationMixin#db_version
14
+ #
15
+ # :singleton-method: db_version
16
+
17
+ ##
18
+ # Force Neo4j.rb to perform migrations
19
+ #
20
+ # === See Also
21
+ # Neo4j::MigrationMixin#migrate!
22
+ #
23
+ # :singleton-method: migrate!
24
+
25
+ ##
26
+ # Specifies a single migration.
27
+ #
28
+ # === Example
29
+ # Notice that the reference node is the context in the up and down blocks.
30
+ #
31
+ # Neo4j.migration 1, :create_articles do
32
+ # up do
33
+ # rels.outgoing(:colours) << Neo4j.new :colour => 'red' << Neo4j.new :colour => 'blue'
34
+ # end
35
+ # down do
36
+ # rels.outgoing(:colours).each {|n| n.del }
37
+ # end
38
+ # end
39
+ #
40
+ # === See Also
41
+ # Neo4j::MigrationMixin::ClassMethods#migration
42
+ # Neo4j::ReferenceNode
43
+ #
44
+ # :singleton-method: migration
45
+
46
+ ##
47
+ # Returns all migrations that has been defined.
48
+ #
49
+ # === See Also
50
+ # Neo4j::MigrationMixin::ClassMethods#migrations
51
+ #
52
+ # :singleton-method: migrations
53
+
54
+ def_delegators :@ref_node, :db_version, :migrate!
55
+ def_delegators Neo4j::ReferenceNode, :migration, :migrations
56
+
57
+
58
+
59
+ # Starts neo4j unless it is not already started.
60
+ # Before using neo4j it has to be started and the location of the Neo database on the file system must
61
+ # have been configured, Neo4j::Config[:storage_path]. You do not have to call this method since
62
+ # neo4j will be started automatically when needed.
63
+ # Registers an at_exit handler that stops neo4j (see Neo4j::stop)
64
+ #
65
+ # === Parameters
66
+ # neo_instance:: optional, an instance of org.neo4j.graphdb.GraphDatabaseService
67
+ #
68
+ # === Examples
69
+ # Neo4j::Config[:storage_path] = '/var/neo4j-db'
70
+ # Neo4j.start
71
+ #
72
+ # === Returns
73
+ # nil
74
+ #
75
+ def start(neo_instance=nil)
76
+ return if running?
77
+ at_exit do
78
+ Neo4j.stop
79
+ end
80
+ @neo = neo_instance || org.neo4j.kernel.EmbeddedGraphDatabase.new(Neo4j::Config[:storage_path])
81
+ @ref_node = Neo4j::Transaction.run do
82
+ ReferenceNode.new(@neo.getReferenceNode())
83
+ end
84
+
85
+ Neo4j::Transaction.run do
86
+ Neo4j.event_handler.neo_started(self)
87
+ end
88
+
89
+ Neo4j::Transaction.run { @ref_node.migrate!}
90
+ nil
91
+ end
92
+
93
+ # Return the org.neo4j.kernel.EmbeddedGraphDatabase
94
+ #
95
+ #
96
+ def instance
97
+ start unless running?
98
+ @neo
99
+ end
100
+
101
+ # Stops the current instance unless it is not started.
102
+ #
103
+ def stop
104
+ if running?
105
+ Neo4j::Transaction.finish # just in case
106
+ @neo.shutdown
107
+ Neo4j.event_handler.neo_stopped(self)
108
+ end
109
+ @neo = nil
110
+ end
111
+
112
+ #
113
+ # Returns true if neo4j is running
114
+ #
115
+ def running?
116
+ !@neo.nil?
117
+ end
118
+
119
+
120
+ # Create a Neo4j::Node
121
+ # This is the same as Neo4j::Node.new.
122
+ # All nodes are created by this method
123
+ def create_node(props = {}) # :nodoc:
124
+ node = instance.createNode
125
+ props.each_pair{|k,v| node[k] = v}
126
+ node
127
+ end
128
+
129
+ # Creates a new Relationship
130
+ # All relationships are created by this method.
131
+ def create_rel(type, from_node, to_node, props = {}) # :nodoc:
132
+ rel = from_node.add_rel(type, to_node)
133
+ props.each_pair {|k,v| rel[k] = v}
134
+ rel
135
+ end
136
+
137
+ # Return a Neo4j node.
138
+ #
139
+ # ==== Parameters
140
+ # node_id:: the unique neo id for one node, should respond to 'to_i'
141
+ # raw:: if the raw Java node object should be returned or the Ruby wrapped node, default false.
142
+ #
143
+ # ==== Returns
144
+ # The node object or nil if not found
145
+ #
146
+ def load_node(node_id, raw = false)
147
+ neo_node = @neo.getNodeById(node_id.to_i)
148
+ if (raw)
149
+ neo_node
150
+ else
151
+ neo_node.wrapper
152
+ end
153
+ rescue org.neo4j.graphdb.NotFoundException
154
+ nil
155
+ end
156
+
157
+
158
+ # Return a Neo4j relationship.
159
+ #
160
+ # ==== Parameters
161
+ # rel_id<String, to_i>:: the unique neo id for one node
162
+ # raw<true|false(default)> :: if the raw Java relationship object should be returned or the Ruby wrapped node.
163
+ #
164
+ # ==== Returns
165
+ # The node object or nil if not found
166
+ #
167
+ def load_rel(rel_id, raw = false)
168
+ neo_rel = @neo.getRelationshipById(rel_id.to_i)
169
+ if (raw)
170
+ neo_rel
171
+ else
172
+ neo_rel.wrapper
173
+ end
174
+ rescue org.neo4j.graphdb.NotFoundException
175
+ nil
176
+ end
177
+
178
+ # Returns all nodes in the node space.
179
+ # Expects a block that will be yield.
180
+ #
181
+ # ==== Parameters
182
+ # raw<true|false(default)> :: if the raw Java node object should be returned or the Ruby wrapped node.
183
+ #
184
+ # ==== Example
185
+ #
186
+ # Neo4j.all_nodes{|node| puts "Node id ${node.neo_id"}
187
+ #
188
+ def all_nodes(raw = false)
189
+ iter = instance.all_nodes.iterator
190
+ while (iter.hasNext)
191
+ id = iter.next.neo_id
192
+ yield load_node(id, raw)
193
+ end
194
+ end
195
+
196
+ # Returns the reference node, which is a "starting point" in the node space.
197
+ #
198
+ # Usually, a client attaches relationships to this node that leads into various parts of the node space.
199
+ # For more information about common node space organizational patterns, see the design guide at http://neo4j.org/doc.
200
+ #
201
+ # ==== Returns
202
+ # The the Neo4j::ReferenceNode
203
+ #
204
+ def ref_node
205
+ @ref_node
206
+ end
207
+
208
+
209
+ # Returns an event handler.
210
+ # This event handler can be used for listen to event such as when the Neo4j is started/stopped or
211
+ # when a node is created/deleted, a property/relationship is changed.
212
+ #
213
+ # ==== Returns
214
+ # a Neo4j::EventHandler instance
215
+ #
216
+ def event_handler
217
+ @event_handler ||= EventHandler.new
218
+ end
219
+
220
+
221
+ def number_of_nodes_in_use
222
+ instance.getConfig().getNeoModule().getNodeManager().getNumberOfIdsInUse(org.neo4j.graphdb.Node.java_class)
223
+ end
224
+
225
+ def number_of_relationships_in_use
226
+ instance.getConfig().getNeoModule().getNodeManager().getNumberOfIdsInUse(org.neo4j.graphdb.Relationship.java_class)
227
+ end
228
+
229
+ def number_of_properties_in_use
230
+ instance.getConfig().getNeoModule().getNodeManager().getNumberOfIdsInUse(org.neo4j.kernel.impl.nioneo.store.PropertyStore.java_class)
231
+ end
232
+
233
+ # Prints some info about the database
234
+ def info
235
+ puts "Neo4j version: #{Neo4j::VERSION}"
236
+ puts "Neo4j db running #{running?}"
237
+ puts "number_of_nodes_in_use: #{number_of_nodes_in_use}"
238
+ puts "number_of_relationships_in_use: #{number_of_relationships_in_use}"
239
+ puts "number_of_properties_in_use: #{number_of_properties_in_use}"
240
+ puts "neo db storage location: #{Neo4j::Config[:storage_path]}"
241
+ puts "lucene index storage location: #{Lucene::Config[:storage_path]}"
242
+ puts "keep lucene index in memory: #{!Lucene::Config[:store_on_file]}"
243
+ end
244
+
245
+ end
246
+ end
247
+
@@ -0,0 +1,49 @@
1
+ module Neo4j
2
+
3
+ org.neo4j.kernel.impl.core.NodeProxy.class_eval do
4
+ include Neo4j::JavaPropertyMixin
5
+ include Neo4j::JavaNodeMixin
6
+ include Neo4j::JavaListMixin
7
+ end
8
+
9
+ # A node in the graph with properties and relationships to other entities.
10
+ # Along with relationships, nodes are the core building blocks of the Neo4j data representation model.
11
+ # Nodes are created by invoking the Neo4j::Node.new method.
12
+ #
13
+ # The new method of this class will return a Java org.neo4j.graphdb.Node
14
+ #
15
+ # === Included Mixins
16
+ # * Neo4j::JavaPropertyMixin (operations that deal with relationships)
17
+ # * Neo4j::JavaNodeMixin (operations that deal with properties
18
+ # * Neo4j::JavaListMixin (operations that deals with list/timeline relationships)
19
+ #
20
+ # (Those mixin are actually not included in the Neo4j::Node but instead directly included in the java class org.neo4j.graphdb.Node)
21
+ #
22
+ # See also the Neo4j::NodeMixin if you want to wrap a node with your own Ruby class.
23
+ #
24
+ class Node
25
+ class << self
26
+ # Returns a org.neo4j.graphdb.Node java object (!)
27
+ # Will trigger a event that the node was created.
28
+ #
29
+ # === Parameters
30
+ # *args :: can be a hash of properties to initialize the node with or empty
31
+ #
32
+ # === Returns
33
+ # org.neo4j.graphdb.Node java object
34
+ #
35
+ # === Examples
36
+ #
37
+ # Neo4j::Node.new
38
+ # Neo4j::Node.new :name => 'foo', :age => 100
39
+ #
40
+ def new(*args)
41
+ node = Neo4j.create_node(args[0] || {})
42
+ yield node if block_given?
43
+ Neo4j.event_handler.node_created(node)
44
+ node
45
+ end
46
+ end
47
+ end
48
+
49
+ end
@@ -0,0 +1,15 @@
1
+ module Neo4j
2
+
3
+ # There is only one reference node in a neo space, which can always been found (Neo4j::Neo#:ref_node).
4
+ # This is a "starting point" in the node space.
5
+ # Usually, a client attaches relationships to this node that leads into various parts of the node space.
6
+ # For more information about common node space organizational patterns, see the design guide at http://neo4j.org/doc.
7
+ #
8
+ # You can add your own has_n or has_list, has_one relationship to this node.
9
+ #
10
+ class ReferenceNode
11
+ include Neo4j::NodeMixin
12
+ include Neo4j::MigrationMixin
13
+ end
14
+
15
+ end
@@ -0,0 +1,85 @@
1
+ module Neo4j
2
+
3
+ org.neo4j.kernel.impl.core.RelationshipProxy.class_eval do
4
+ include Neo4j::JavaPropertyMixin
5
+ include Neo4j::JavaRelationshipMixin
6
+
7
+ def end_node # :nodoc:
8
+ id = getEndNode.getId
9
+ Neo4j.load_node(id)
10
+ end
11
+
12
+ def start_node # :nodoc:
13
+ id = getStartNode.getId
14
+ Neo4j.load_node(id)
15
+ end
16
+
17
+ def other_node(node) # :nodoc:
18
+ neo_node = node
19
+ neo_node = node._java_node if node.respond_to?(:_java_node)
20
+ id = getOtherNode(neo_node).getId
21
+ Neo4j.load_node(id)
22
+ end
23
+ end
24
+
25
+ #
26
+ # A relationship between two nodes in the graph. A relationship has a start node, an end node and a type.
27
+ # You can attach properties to relationships with the API specified in Neo4j::JavaPropertyMixin.
28
+ #
29
+ # Relationship are created by invoking the << operator on the rels method on the node as follow:
30
+ # node.rels.outgoing(:friends) << other_node << yet_another_node
31
+ #
32
+ # or using the Neo4j::Relationship#new method (which does the same thing):
33
+ # rel = Neo4j::Relationship.new(:friends, node, other_node)
34
+ #
35
+ # The fact that the relationship API gives meaning to start and end nodes implicitly means that all relationships have a direction.
36
+ # In the example above, rel would be directed from node to otherNode.
37
+ # A relationship's start node and end node and their relation to outgoing and incoming are defined so that the assertions in the following code are true:
38
+ #
39
+ # a = Neo4j::Node.new
40
+ # b = Neo4j::Node.new
41
+ # rel = Neo4j::Relationship.new(:some_type, a, b)
42
+ # # Now we have: (a) --- REL_TYPE ---> (b)
43
+ #
44
+ # rel.start_node # => a
45
+ # rel.end_node # => b
46
+ #
47
+ # Furthermore, Neo4j guarantees that a relationship is never "hanging freely,"
48
+ # i.e. start_node, end_node and other_node are guaranteed to always return valid, non-null nodes.
49
+ #
50
+ # See also the Neo4j::RelationshipMixin if you want to wrap a relationship with your own Ruby class.
51
+ #
52
+ # === Included Mixins
53
+ # * Neo4j::JavaPropertyMixin
54
+ # * Neo4j::JavaRelationshipMixin
55
+ #
56
+ # (Those mixin are actually not included in the Neo4j::Relationship but instead directly included in the java class org.neo4j.kernel.impl.core.RelationshipProxy)
57
+ #
58
+ class Relationship
59
+ class << self
60
+ # Returns a org.neo4j.graphdb.Relationship java object (!)
61
+ # Will trigger a event that the relationship was created.
62
+ #
63
+ # === Parameters
64
+ # type :: the type of relationship
65
+ # from_node :: the start node of this relationship
66
+ # end_node :: the end node of this relationship
67
+ # props :: optional properties for the created relationship
68
+ #
69
+ # === Returns
70
+ # org.neo4j.graphdb.Relationship java object
71
+ #
72
+ # === Examples
73
+ #
74
+ # Neo4j::Relationship.new :friend, node1, node2, :since => '2001-01-02', :status => 'okey'
75
+ #
76
+ def new(type, from_node, to_node, props={})
77
+ Neo4j.create_rel(type, from_node, to_node, props)
78
+ end
79
+ end
80
+
81
+ end
82
+
83
+ end
84
+
85
+
@@ -0,0 +1,164 @@
1
+ module Neo4j
2
+
3
+ module Relationships
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::Relationships::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
+
36
+ attr_reader :to_type, :to_class, :cascade_delete_prop_name, :counter, :rel_id
37
+ CASCADE_DELETE_PROP_NAMES = { :outgoing => :_cascade_delete_outgoing, :incoming => :_cascade_delete_incoming}
38
+
39
+ def initialize(rel_id, params)
40
+ @outgoing = true
41
+ @rel_id = rel_id
42
+ @to_type = rel_id
43
+ @namespace_type = rel_id
44
+ @cascade_delete_prop_name = CASCADE_DELETE_PROP_NAMES[params[:cascade_delete]]
45
+ @counter = params[:counter] == true
46
+ end
47
+
48
+ # If a counter was specified in the dsl for counting number of nodes in this relationship.
49
+ #
50
+ def counter?
51
+ @counter
52
+ end
53
+
54
+ # If cascade delete was specified for this relationship
55
+ #
56
+ def cascade_delete?
57
+ !@cascade_delete_prop_name.nil?
58
+ end
59
+
60
+ def class_and_type_from_args(args) # :nodoc:
61
+ if (args.size > 1)
62
+ return args[0], args[1]
63
+ else
64
+ return args[0], @rel_id
65
+ end
66
+ end
67
+
68
+
69
+ # The actual relationship type that this DSL will use
70
+ def namespace_type
71
+ @to_class.nil? ? @to_type.to_s : "#{@to_class.to_s}##{@to_type.to_s}"
72
+ end
73
+
74
+
75
+ # The direction of the relationships
76
+ # ==== Returns
77
+ # <tt>:outgoing::</tt> or <tt>:incoming</tt>
78
+ def direction
79
+ (outgoing?)? :outgoing : :incoming
80
+ end
81
+
82
+ def outgoing?
83
+ @outgoing
84
+ end
85
+
86
+
87
+ # Specifies an outgoing relationship.
88
+ # The name of the outgoing class will be used as a prefix for the relationship used.
89
+ #
90
+ # ==== Arguments
91
+ # clazz:: to which class this relationship goes
92
+ # relationship:: optional, the relationship to use
93
+ #
94
+ # ==== Example
95
+ # class FolderNode
96
+ # include Neo4j::NodeMixin
97
+ # has_n(:files).to(FileNode)
98
+ # end
99
+ #
100
+ # folder = FolderNode.new
101
+ # # generate a relationship between folder and file of type 'FileNode#files'
102
+ # folder.files << FileNode.new
103
+ #
104
+ def to(*args)
105
+ @outgoing = true
106
+ @to_class, @to_type = class_and_type_from_args(args)
107
+ self
108
+ end
109
+
110
+ # Specifies an incoming relationship.
111
+ # Will use the outgoing relationship given by the from class.
112
+ #
113
+ # ==== Example
114
+ # class FolderNode
115
+ # include Neo4j::NodeMixin
116
+ # has_n(:files).to(FileNode)
117
+ # end
118
+ #
119
+ # class FileNode
120
+ # include Neo4j::NodeMixin
121
+ # has_one(:folder).from(FileNode, :files)
122
+ # end
123
+ #
124
+ # file = FileNode.new
125
+ # # create an outgoing relationship of type 'FileNode#files' from folder node to file
126
+ # file.folder = FolderNode.new
127
+ #
128
+ def from(*args) #(clazz, type)
129
+ @outgoing = false
130
+ @to_class, @to_type = class_and_type_from_args(args)
131
+ self
132
+ end
133
+
134
+ # Specifies which relationship ruby class to use for the relationship
135
+ #
136
+ # ==== Example
137
+ #
138
+ # class OrderLine
139
+ # include Neo4j::RelationshipMixin
140
+ # property :units
141
+ # property :unit_price
142
+ # end
143
+ #
144
+ # class Order
145
+ # property :total_cost
146
+ # property :dispatched
147
+ # has_n(:products).to(Product).relationship(OrderLine)
148
+ # end
149
+ #
150
+ # order = Order.new
151
+ # order.products << Product.new
152
+ # order.products_rels.first # => OrderLine
153
+ #
154
+ def relationship(rel_class)
155
+ @relationship = rel_class
156
+ self
157
+ end
158
+
159
+ def relationship_class # :nodoc:
160
+ @relationship
161
+ end
162
+ end
163
+ end
164
+ end