neo4j-core 0.0.14-java → 0.0.15-java

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -20,7 +20,7 @@ The Neo4j module is public and the Neo4j::Core(::*) are internal modules.
20
20
 
21
21
  {Neo4j} The Database
22
22
 
23
- {Neo4j::Cypher} Cypher Query Generator, see RSpec spec/neo4j/cypher_spec
23
+ {Neo4j::Cypher} Cypher Query DSL, see {Neo4j Wiki}[https://github.com/andreasronge/neo4j/wiki/Neo4j%3A%3ACore-Cypher]
24
24
 
25
25
  {Neo4j::Algo} Included algorithms, like shortest path
26
26
 
data/lib/neo4j/cypher.rb CHANGED
@@ -1,5 +1,14 @@
1
1
  module Neo4j
2
+
3
+ # Generates a Cypher string from a Ruby DSL.
4
+ # This class is used by the {Ņeo4j#query} method.
5
+ # Methods on in this class returns object from the {Neo4j::Core::Cypher} module (e.g. {Neo4j::Cypher#node} can return a #{Neo4j::Core::Cypher::StartNode}).
6
+ #
7
+ # @example usage
8
+ # Neo4j::Cypher.new { node }
9
+ #
2
10
  class Cypher
11
+ # @private
3
12
  attr_reader :expressions
4
13
 
5
14
  include Neo4j::Core::Cypher
@@ -20,6 +29,7 @@ module Neo4j
20
29
  # @param args the argument for the dsl_block
21
30
  # @yield the block which will be evaluated in the context of this object in order to create an Cypher Query string
22
31
  # @yieldreturn [Return, Object] If the return is not an instance of Return it will be converted it to a Return object (if possible).
32
+ # @see Neo4j::Core::Cypher
23
33
  def initialize(*args, &dsl_block)
24
34
  @expressions = []
25
35
  @variables = []
data/lib/neo4j/neo4j.rb CHANGED
@@ -58,9 +58,10 @@ module Neo4j
58
58
  end
59
59
 
60
60
  # Checks read only mode of the database. Only one process can have write access to the database.
61
+ # It will always return false if the database is not started yet.
61
62
  # @return [true, false] if the database has started up in read only mode
62
63
  def read_only?
63
- (@db && @db.graph && @db.read_only?)
64
+ !!(@db && @db.graph && @db.read_only?)
64
65
  end
65
66
 
66
67
  # Returns a started db instance. Starts it's not running.
@@ -1,5 +1,9 @@
1
1
  module Neo4j
2
2
  module Core
3
+
4
+ # This module contains a number of mixins and classes used by the neo4j.rb cypher DSL.
5
+ # The Cypher DSL is evaluated in the context of {Neo4j::Cypher} which contains a number of methods (e.g. {Neo4j::Cypher#node})
6
+ # which returns classes from this module.
3
7
  module Cypher
4
8
 
5
9
  module MathFunctions
@@ -19,6 +23,7 @@ module Neo4j
19
23
  _add_math_func(:sign, value)
20
24
  end
21
25
 
26
+ # @private
22
27
  def _add_math_func(name, value=nil)
23
28
  value ||= self.respond_to?(:var_name) ? self.var_name : to_s
24
29
  expressions.delete(self)
@@ -119,23 +124,27 @@ module Neo4j
119
124
  self
120
125
  end
121
126
 
127
+ # generates a <tt>ID</tt> cypher fragment.
122
128
  def neo_id
123
129
  Property.new(@expressions, self, 'ID').to_function!
124
130
  end
125
131
 
132
+ # generates a <tt>has</tt> cypher fragment.
126
133
  def property?(p)
127
134
  p = Property.new(expressions, self, p)
128
135
  p.binary_operator("has")
129
136
  end
130
137
 
138
+ # generates a <tt>is null</tt> cypher fragment.
131
139
  def exist?
132
140
  p = Property.new(expressions, self, p)
133
141
  p.binary_operator("", " is null")
134
142
  end
135
143
 
144
+ # Can be used instead of [_classname] == klass
136
145
  def is_a?(klass)
137
- return super if klass.class != Class || !klass.instance_methods.include?("wrapper")
138
- super
146
+ return super if klass.class != Class || !klass.respond_to?(:_load_wrapper)
147
+ self[:_classname] == klass.to_s
139
148
  end
140
149
  end
141
150
 
@@ -236,7 +245,16 @@ module Neo4j
236
245
 
237
246
  end
238
247
 
248
+ # A property is returned from a Variable by using the [] operator.
249
+ #
250
+ # It has a number of useful method like
251
+ # <tt>count</tt>, <tt>sum</tt>, <tt>avg</tt>, <tt>min</tt>, <tt>max</tt>, <tt>collect</tt>, <tt>head</tt>, <tt>last</tt>, <tt>tail</tt>,
252
+ #
253
+ # @example
254
+ # n=node(2, 3, 4); n[:name].collect
255
+ # # same as START n0=node(2,3,4) RETURN collect(n0.property)
239
256
  class Property
257
+ # @private
240
258
  attr_reader :expressions, :var_name
241
259
  include Comparable
242
260
  include MathOperator
@@ -250,17 +268,20 @@ module Neo4j
250
268
  @var_name = @prop_name ? "#{@var.to_s}.#{@prop_name}" : @var.to_s
251
269
  end
252
270
 
271
+ # @private
253
272
  def to_function!(var = @var.to_s)
254
273
  @var_name = "#{@prop_name}(#{var})"
255
274
  self
256
275
  end
257
276
 
277
+ # Make it possible to rename a property with a different name (AS)
258
278
  def as(new_name)
259
279
  @var_name = "#{@var_name} AS #{new_name}"
260
280
  end
261
281
 
262
282
  # required by the Predicate Methods Module
263
283
  # @see PredicateMethods
284
+ # @private
264
285
  def iterable
265
286
  var_name
266
287
  end
@@ -269,10 +290,12 @@ module Neo4j
269
290
  self
270
291
  end
271
292
 
293
+ # @private
272
294
  def in?(values)
273
295
  binary_operator("", " IN [#{values.map { |x| %Q["#{x}"] }.join(',')}]")
274
296
  end
275
297
 
298
+ # Only return distinct values/nodes/rels/paths
276
299
  def distinct
277
300
  @var_name = "distinct #{@var_name}"
278
301
  self
@@ -290,16 +313,19 @@ module Neo4j
290
313
  end
291
314
  end
292
315
 
316
+ # @private
293
317
  def function(func_name_pre, func_name_post = "")
294
318
  ExprOp.new(self, nil, func_name_pre, func_name_post)
295
319
  end
296
320
 
321
+ # @private
297
322
  def binary_operator(op, post_fix = "")
298
323
  ExprOp.new(self, nil, op, post_fix).binary!
299
324
  end
300
325
  end
301
326
 
302
327
  class Start < Expression
328
+ # @private
303
329
  attr_reader :var_name
304
330
  include Variable
305
331
  include Matchable
@@ -311,7 +337,9 @@ module Neo4j
311
337
 
312
338
  end
313
339
 
340
+ # Can be created from a <tt>node</tt> dsl method.
314
341
  class StartNode < Start
342
+ # @private
315
343
  attr_reader :nodes
316
344
 
317
345
  def initialize(nodes, expressions)
@@ -325,7 +353,10 @@ module Neo4j
325
353
  end
326
354
  end
327
355
 
356
+
357
+ # Can be created from a <tt>rel</tt> dsl method.
328
358
  class StartRel < Start
359
+ # @private
329
360
  attr_reader :rels
330
361
 
331
362
  def initialize(rels, expressions)
@@ -381,10 +412,12 @@ module Neo4j
381
412
  opts.each_pair { |k, v| self.send(k, v) }
382
413
  end
383
414
 
415
+ # @private
384
416
  def return_method
385
417
  @name_or_ref.respond_to?(:return_method) && @name_or_ref.return_method
386
418
  end
387
419
 
420
+ # @private
388
421
  def as_return_method
389
422
  if return_method[:bracket]
390
423
  "#{return_method[:name]}(#@var_name)"
@@ -432,6 +465,7 @@ module Neo4j
432
465
  end
433
466
  end
434
467
 
468
+ # Can be used to skip result from a return clause
435
469
  class Skip < Expression
436
470
  def initialize(expressions, value)
437
471
  super(expressions, :skip)
@@ -443,6 +477,7 @@ module Neo4j
443
477
  end
444
478
  end
445
479
 
480
+ # Can be used to limit result from a return clause
446
481
  class Limit < Expression
447
482
  def initialize(expressions, value)
448
483
  super(expressions, :limit)
@@ -479,8 +514,11 @@ module Neo4j
479
514
  end
480
515
  end
481
516
 
517
+ # Created from a node's match operator like >> or <.
482
518
  class Match < Expression
519
+ # @private
483
520
  attr_reader :dir, :expressions, :left, :right, :var_name, :dir_op
521
+ # @private
484
522
  attr_accessor :algorithm, :next, :prev
485
523
  include Variable
486
524
 
@@ -495,19 +533,29 @@ module Neo4j
495
533
  end
496
534
 
497
535
 
536
+ # Generates a <tt>x in nodes(m3)</tt> cypher expression.
537
+ #
538
+ # @example
539
+ # p.nodes.all? { |x| x[:age] > 30 }
498
540
  def nodes
499
541
  Entities.new(@expressions, "nodes", self)
500
542
  end
501
543
 
544
+ # Generates a <tt>x in relationships(m3)</tt> cypher expression.
545
+ #
546
+ # @example
547
+ # p.relationships.all? { |x| x[:age] > 30 }
502
548
  def rels
503
549
  Entities.new(@expressions, "relationships", self)
504
550
  end
505
551
 
552
+ # returns the length of the path
506
553
  def length
507
554
  self.return_method = {:name => 'length', :bracket => true}
508
555
  self
509
556
  end
510
557
 
558
+ # @private
511
559
  def find_match_start
512
560
  c = self
513
561
  while (c.prev) do
@@ -516,26 +564,32 @@ module Neo4j
516
564
  c
517
565
  end
518
566
 
567
+ # @private
519
568
  def left_var_name
520
569
  @left.respond_to?(:var_name) ? @left.var_name : @left.to_s
521
570
  end
522
571
 
572
+ # @private
523
573
  def right_var_name
524
574
  @right.respond_to?(:var_name) ? @right.var_name : @right.to_s
525
575
  end
526
576
 
577
+ # @private
527
578
  def right_expr
528
579
  @right.respond_to?(:expr) ? @right.expr : right_var_name
529
580
  end
530
581
 
582
+ # @private
531
583
  def referenced!
532
584
  @referenced = true
533
585
  end
534
586
 
587
+ # @private
535
588
  def referenced?
536
589
  !!@referenced
537
590
  end
538
591
 
592
+ # @private
539
593
  def to_s
540
594
  curr = find_match_start
541
595
  result = (referenced? || curr.referenced?) ? "#{var_name} = " : ""
@@ -548,6 +602,8 @@ module Neo4j
548
602
  end
549
603
  end
550
604
 
605
+ # The left part of a match clause, e.g. node < rel(':friends')
606
+ # Can return {MatchRelRight} using a match operator method.
551
607
  class MatchRelLeft < Match
552
608
  def initialize(left, right, expressions, dir)
553
609
  super(left, right, expressions, dir, dir == :incoming ? '<-' : '-')
@@ -619,6 +675,7 @@ module Neo4j
619
675
  "#{dir_op}(#{right_var_name})"
620
676
  end
621
677
 
678
+ # negate this match
622
679
  def not
623
680
  expressions.delete(self)
624
681
  ExprOp.new(left, nil, "not").binary!
@@ -635,6 +692,8 @@ module Neo4j
635
692
 
636
693
  end
637
694
 
695
+ # The right part of a match clause (node_b), e.g. node_a > rel(':friends') > node_b
696
+ #
638
697
  class MatchNode < Match
639
698
  attr_reader :dir_op
640
699
 
@@ -67,7 +67,8 @@ module Neo4j
67
67
  end
68
68
 
69
69
 
70
- def running? #:nodoc:
70
+ # true if the database has started
71
+ def running?
71
72
  @running
72
73
  end
73
74
 
@@ -1,9 +1,9 @@
1
1
  module Neo4j
2
2
  module Core
3
3
 
4
- # Implements the Neo4j PruneEvaluator Java interface, only used internally.
5
- # @private
6
4
  module Traversal
5
+ # Implements the Neo4j PruneEvaluator Java interface, only used internally.
6
+ # @private
7
7
  class PruneEvaluator
8
8
  include Java::OrgNeo4jGraphdbTraversal::PruneEvaluator
9
9
 
@@ -1,5 +1,5 @@
1
1
  module Neo4j
2
2
  module Core
3
- VERSION = "0.0.14"
3
+ VERSION = "0.0.15"
4
4
  end
5
5
  end
data/neo4j-core.gemspec CHANGED
@@ -27,5 +27,5 @@ It comes included with the Apache Lucene document database.
27
27
  s.extra_rdoc_files = %w( README.rdoc )
28
28
  s.rdoc_options = ["--quiet", "--title", "Neo4j::Core", "--line-numbers", "--main", "README.rdoc", "--inline-source"]
29
29
 
30
- s.add_dependency("neo4j-community", "1.7.0")
30
+ s.add_dependency("neo4j-community", ">= 1.7.0")
31
31
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: neo4j-core
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.14
5
+ version: 0.0.15
6
6
  platform: java
7
7
  authors:
8
8
  - Andreas Ronge
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-04-24 00:00:00 Z
13
+ date: 2012-04-27 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: neo4j-community
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirement: &id001 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
- - - "="
21
+ - - ">="
22
22
  - !ruby/object:Gem::Version
23
23
  version: 1.7.0
24
24
  type: :runtime