neo4j-core 0.0.10-java → 0.0.11-java

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -10,6 +10,7 @@ The Neo4j module is public and the Neo4j::Core(::*) are internal modules.
10
10
  == Documentation
11
11
 
12
12
  * {YARD}[http://rdoc.info/github/andreasronge/neo4j-core/file/README.rdoc]
13
+ * {Neo4j.rb Wiki}[https://github.com/andreasronge/neo4j/wiki/]
13
14
 
14
15
  == The public API
15
16
 
@@ -311,6 +311,7 @@ module Neo4j
311
311
 
312
312
  def initialize(nodes, expressions)
313
313
  super("n", expressions)
314
+
314
315
  @nodes = nodes.map { |n| n.respond_to?(:neo_id) ? n.neo_id : n }
315
316
  end
316
317
 
@@ -451,23 +452,25 @@ module Neo4j
451
452
  class OrderBy < Expression
452
453
  def initialize(expressions)
453
454
  super(expressions, :order_by)
455
+ @orders = []
454
456
  end
455
457
 
456
458
  def asc(props)
457
- @asc ||= []
458
- @asc += props
459
+ @orders << [:asc, props]
459
460
  end
460
461
 
461
462
  def desc(props)
462
- @desc ||= []
463
- @desc += props
463
+ @orders << [:desc, props]
464
464
  end
465
465
 
466
466
  def to_s
467
- s = []
468
- s << @asc.map { |p| p.var_name }.join(",") if @asc
469
- s << @desc.map { |p| p.var_name.to_s + " DESC" }.join(",") if @desc
470
- s.join(',')
467
+ @orders.map do |pair|
468
+ if pair[0] == :asc
469
+ pair[1].map(&:var_name).join(', ')
470
+ else
471
+ pair[1].map(&:var_name).join(', ') + " DESC"
472
+ end
473
+ end.join(', ')
471
474
  end
472
475
  end
473
476
 
@@ -681,6 +684,7 @@ module Neo4j
681
684
  attr_reader :expressions
682
685
 
683
686
  def initialize(expressions, variables)
687
+ variables ||= []
684
688
  @var_name = "v#{variables.size}"
685
689
  variables << self
686
690
  @variables = variables
@@ -1,12 +1,21 @@
1
1
  module Neo4j
2
2
  module Core
3
3
  module Cypher
4
- # Wraps the Cypher query result
5
- # Loads the wrapper if possible and use symbol as keys.
4
+ # Wraps the Cypher query result.
5
+ # Loads the node and relationships wrapper if possible and use symbol as column keys.
6
+ # @notice The result is a once forward read only Enumerable, work if you need to read the result twice - use #to_a
7
+ #
8
+ # @example
9
+ # result = Neo4j.query(@a, @b){|a,b| node(a,b).as(:n)}
10
+ # r = @query_result.to_a # can only loop once
11
+ # r.size.should == 2
12
+ # r.first.should include(:n)
13
+ # r[0][:n].neo_id.should == @a.neo_id
14
+ # r[1][:n].neo_id.should == @b.neo_id
6
15
  class ResultWrapper
7
16
  include Enumerable
8
17
 
9
- # @return the original result from the Neo4j Cypher Engine
18
+ # @return the original result from the Neo4j Cypher Engine, once forward read only !
10
19
  attr_reader :source
11
20
 
12
21
  def initialize(source)
@@ -23,7 +32,7 @@ module Neo4j
23
32
  @source.each { |row| yield map(row) }
24
33
  end
25
34
 
26
- # Maps each row
35
+ # Maps each row so that we can use symbols for column names.
27
36
  # @private
28
37
  def map(row)
29
38
  out = {} # move to a real hash!
@@ -26,9 +26,7 @@ module Neo4j
26
26
 
27
27
  # Implements the Ruby Enumerable mixin
28
28
  def each
29
- iter = iterator
30
- while (iter.has_next())
31
- rel = iter.next
29
+ iterator.each do |rel|
32
30
  yield rel.wrapper if match_between?(rel)
33
31
  end
34
32
  end
@@ -1,5 +1,5 @@
1
1
  module Neo4j
2
2
  module Core
3
- VERSION = "0.0.10"
3
+ VERSION = "0.0.11"
4
4
  end
5
5
  end
data/lib/neo4j/cypher.rb CHANGED
@@ -23,7 +23,21 @@ module Neo4j
23
23
  def initialize(*args, &dsl_block)
24
24
  @expressions = []
25
25
  @variables = []
26
- res = self.instance_exec(*args, &dsl_block)
26
+ to_dsl_args = args.map do |a|
27
+ case
28
+ when a.is_a?(Array) && a.first.respond_to?(:_java_node)
29
+ StartNode.new(a, @expressions)
30
+ when a.is_a?(Array) && a.first.respond_to?(:_java_rel)
31
+ StartRel.new(a, @expressions)
32
+ when a.respond_to?(:_java_node)
33
+ StartNode.new([a], @expressions)
34
+ when a.respond_to?(:_java_rel)
35
+ StartRel.new([a], @expressions)
36
+ else
37
+ a
38
+ end
39
+ end
40
+ res = self.instance_exec(*to_dsl_args, &dsl_block)
27
41
  unless res.kind_of?(Return)
28
42
  res.respond_to?(:to_a) ? ret(*res) : ret(res)
29
43
  end
data/lib/neo4j/neo4j.rb CHANGED
@@ -97,6 +97,10 @@ module Neo4j
97
97
  # q.first[:n] #=> the @node
98
98
  # q.columns.first => :n
99
99
  #
100
+ # @example Using an array of nodes
101
+ # # same as - two_nodes=node(Neo4j.ref_node.neo_id, node_b.neo_id), b = node(b.neo_id)
102
+ # q = Neo4j.query([Neo4j.ref_node, node_b], node_c){|two_nodes, b| two_nodes <=> b; b}
103
+ #
100
104
  # @example With an string
101
105
  # q = Neo4j._query("START n=node(42) RETURN n")
102
106
  # q.first(:n) #=> the @node
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.10
5
+ version: 0.0.11
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-17 00:00:00 Z
13
+ date: 2012-04-19 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: neo4j-community