neo4j 1.1.0.beta.2-java → 1.1.0.beta.3-java

Sign up to get free protection for your applications and to get access to all the features.
data/CONTRIBUTORS CHANGED
@@ -3,6 +3,7 @@ Maintainer:
3
3
 
4
4
  Contributors:
5
5
 
6
+ * Joe Leaver
6
7
  * Junegunn Choi
7
8
  * Jay Adkisson
8
9
  * Stephan Hagemann
@@ -10,7 +10,7 @@ module Neo4j
10
10
 
11
11
  extend ActiveModel::Callbacks
12
12
 
13
- define_model_callbacks :create, :save, :update, :destroy
13
+ define_model_callbacks :create, :save, :update, :destroy, :validation
14
14
  end
15
15
 
16
16
  def destroy_with_callbacks #:nodoc:
@@ -54,12 +54,39 @@ module Neo4j
54
54
 
55
55
  def find(*args, &block)
56
56
  return super(*args, &block) if block
57
- node = args.first
58
- enum = Enumerator.new(@storage, :each_rel, @dir)
59
- if @dir == :incoming
60
- enum.find{|r| r.start_node == node}
57
+
58
+ case args.first
59
+ when :all, :first
60
+ kind = args.shift
61
+ send(kind, *args)
62
+ when "0", 0
63
+ nil
64
+ else
65
+ if ((args.first.is_a?(Integer) || args.first.is_a?(String)) && args.first.to_i > 0)
66
+ find_by_id(*args)
67
+ else
68
+ first(*args)
69
+ end
70
+ end
71
+ end
72
+
73
+ def all(*args)
74
+ unless args.empty?
75
+ enum = Enumerator.new(@storage, :each_node, @dir).find{|n| n == args.first}
61
76
  else
62
- enum.find{|r| r.end_node == node}
77
+ enum = Enumerator.new(@storage, :each_node, @dir)
78
+ end
79
+ end
80
+
81
+ def first(*args)
82
+ if result = all(*args)
83
+ if result.respond_to?(:collect) #if it's enumerable, get the first result
84
+ result.first
85
+ else
86
+ result
87
+ end
88
+ else
89
+ nil
63
90
  end
64
91
  end
65
92
 
@@ -89,9 +116,21 @@ module Neo4j
89
116
  size == 0 # TODO, performance: there are probably faster way of doing this
90
117
  end
91
118
 
119
+ def blank?
120
+ false unless size == 0
121
+ end
122
+
92
123
  def to_s
93
124
  "Node dir: #{@dir}, #{@storage}"
94
125
  end
126
+
127
+ protected
128
+
129
+
130
+ def find_by_id(*args)
131
+ result = Enumerator.new(@storage, :each_node, @dir).find{|n| n.id.to_i == args.first.to_i}
132
+ end
133
+
95
134
  end
96
135
  end
97
136
  end
@@ -61,14 +61,47 @@ module Neo4j
61
61
 
62
62
  def find(*args, &block)
63
63
  return super(*args, &block) if block
64
- node = args.first
65
- if @dir == :incoming
66
- find{|r| r.start_node == node}
64
+
65
+ case args.first
66
+ when :all, :first
67
+ kind = args.shift
68
+ send(kind, *args)
69
+ when "0", 0
70
+ nil
71
+ else
72
+ if ((args.first.is_a?(Integer) || args.first.is_a?(String)) && args.first.to_i > 0)
73
+ find_by_id(*args)
74
+ else
75
+ first(*args)
76
+ end
77
+ end
78
+ end
79
+
80
+ def all(*args)
81
+ if args.first.class == Neo4j::Rails::Relationship #arg is a relationship
82
+ find_all{|r| r == args.first}
83
+ elsif ((args.first.is_a?(Integer) || args.first.is_a?(String)) && args.first.to_i > 0) #arg is an int
84
+ find_all{|r| r.start_node.id.to_i == args.first.to_i || r.end_node.id.to_i == args.first.to_i}
85
+ elsif node_in?(*args) #arg is a node
86
+ find_all{|r| r.start_node == args.first || r.end_node == args.first}
87
+ else #there either aren't any args, or we don't understand them
88
+ collect
89
+ end
90
+ end
91
+
92
+ def first(*args)
93
+ if result = all(*args)
94
+ if result.respond_to?(:collect) #if it's enumerable, get the first result
95
+ result.first
96
+ else
97
+ result
98
+ end
67
99
  else
68
- find{|r| r.end_node == node}
100
+ nil
69
101
  end
70
102
  end
71
103
 
104
+
72
105
  def [](index)
73
106
  i = 0
74
107
  each{|x| return x if i == index; i += 1}
@@ -85,6 +118,22 @@ module Neo4j
85
118
  "Rels dir: #{@dir}, #{@storage}"
86
119
  end
87
120
 
121
+ protected
122
+
123
+ def node_in?(*args)
124
+ # does it contain an string, which will be treated like a condition ?
125
+ if args.find { |a| a.class.superclass == Neo4j::Rails::Model }
126
+ return true
127
+ else
128
+ return false
129
+ end
130
+ end
131
+
132
+ def find_by_id(*args)
133
+ find{|r| r.id.to_i == args.first.to_i}
134
+ end
135
+
136
+
88
137
  end
89
138
  end
90
139
  end
data/lib/neo4j/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Neo4j
2
- VERSION = "1.1.0.beta.2"
2
+ VERSION = "1.1.0.beta.3"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: neo4j
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 1.1.0.beta.2
5
+ version: 1.1.0.beta.3
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: 2011-05-02 00:00:00 +02:00
13
+ date: 2011-05-10 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency